Skip to content

Instantly share code, notes, and snippets.

@alantsai
Created January 30, 2017 14:32
Show Gist options
  • Save alantsai/7205e3a5513a66e2d1ae162ad23054e9 to your computer and use it in GitHub Desktop.
Save alantsai/7205e3a5513a66e2d1ae162ad23054e9 to your computer and use it in GitHub Desktop.
Delete files from zip file using powershell #powershell
# original from http://stackoverflow.com/questions/20269202/remove-files-from-zip-file-with-powershell
# 這邊是從某個zip檔案裡面的對應對應files刪掉
[Reflection.Assembly]::LoadWithPartialName('System.IO.Compression')
$zipfile = 'C:\path\to\your.zip'
$files = 'some.file', 'other.file', ...
$stream = New-Object IO.FileStream($zipfile, [IO.FileMode]::Open)
$mode = [IO.Compression.ZipArchiveMode]::Update
$zip = New-Object IO.Compression.ZipArchive($stream, $mode)
($zip.Entries | ? { $files -contains $_.Name }) | % { $_.Delete() }
$zip.Dispose()
$stream.Close()
$stream.Dispose()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment