Skip to content

Instantly share code, notes, and snippets.

@daicham
Last active January 9, 2019 13:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save daicham/4528511 to your computer and use it in GitHub Desktop.
Save daicham/4528511 to your computer and use it in GitHub Desktop.
zip/unzip on Powershell (depends on Ionic.Zip.dll)
function zip ($zipFilePath, $targetDir) {
# load Ionic.Zip.dll
[System.Reflection.Assembly]::LoadFrom(path\to\Ionic.Zip.dll)
$encoding = [System.Text.Encoding]::GetEncoding("shift_jis") # 日本語のファイルを扱うために必要
$zipfile = new-object Ionic.Zip.ZipFile($encoding)
$zipfile.AddDirectory($targetDir)
if (!(test-path (split-path $zipFilePath -parent))) {
mkdir (split-path $zipFilePath -parent)
}
write-host "Saving... zip file from $targetDir"
$zipfile.Save($zipFilePath)
$zipfile.Dispose()
write-host "Saved."
}
function unzip ($zipFilePath, $targetDir) {
# load Ionic.Zip.dll
[System.Reflection.Assembly]::LoadFrom(path\to\Ionic.Zip.dll)
$encoding = [System.Text.Encoding]::GetEncoding("shift_jis") # 日本語のファイルを扱うために必要
$zipfile = new-object Ionic.Zip.ZipFile($encoding)
if (!(test-path (split-path $targetDir -parent))) {
mkdir (split-path $targetDir -parent)
}
write-host "Extracting... zip file[$zipFilePath] to $targetDir"
$zip = [Ionic.Zip.ZIPFile]::Read($zipFilePath, $encoding)
$zip | %{$_.Extract($targetDir, [Ionic.Zip.ExtractExistingFileAction]::OverWriteSilently)}
write-host "Extracted."
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment