Created
January 30, 2017 14:32
-
-
Save alantsai/7205e3a5513a66e2d1ae162ad23054e9 to your computer and use it in GitHub Desktop.
Delete files from zip file using powershell #powershell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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