PowerShellコマンドで作成
function Create-Zip {
param (
[string]$sourcePath,
[string]$destinationPath
)
if (Test-Path $sourcePath) {
Compress-Archive -Path $sourcePath -DestinationPath $destinationPath
Write-Output "ZIPファイルが作成されました: $destinationPath"
} else {
Write-Output "指定されたパスが存在しません: $sourcePath"
}
}
# 使用例
Create-Zip -sourcePath "C:\\path\\to\\your\\folder" -destinationPath "C:\\path\\to\\your\\output.zip"
.NET frameworkで作成
Add-Type -AssemblyName System.IO.Compression.FileSystem
function Create-Zip {
param (
[string]$sourcePath,
[string]$destinationPath
)
try {
if (Test-Path $sourcePath) {
[System.IO.Compression.ZipFile]::CreateFromDirectory($sourcePath, $destinationPath)
Write-Output "ZIPファイルが作成されました: $destinationPath"
} else {
Write-Output "指定されたパスが存在しません: $sourcePath"
}
} catch {
Write-Output "エラーが発生しました: $_"
}
}
# 使用例
Create-Zip -sourcePath "C:\\path\\to\\your\\folder" -destinationPath "C:\\path\\to\\your\\output.zip"