说 foo.zip
包含:
a
b
c
|- c1.exe
|- c2.dll
|- c3.dll
哪里
a, b, c
是文件夹。如果我
Expand-Archive .\foo.zip -DestinationPath foo
foo.zip
中的所有文件/文件夹被提取。我只想提取
c
文件夹。
最佳答案
尝试这个
Add-Type -Assembly System.IO.Compression.FileSystem
#extract list entries for dir myzipdir/c/ into myzipdir.zip
$zip = [IO.Compression.ZipFile]::OpenRead("c:\temp\myzipdir.zip")
$entries=$zip.Entries | where {$_.FullName -like 'myzipdir/c/*' -and $_.FullName -ne 'myzipdir/c/'}
#create dir for result of extraction
New-Item -ItemType Directory -Path "c:\temp\c" -Force
#extraction
$entries | foreach {[IO.Compression.ZipFileExtensions]::ExtractToFile( $_, "c:\temp\c\" + $_.Name) }
#free object
$zip.Dispose()
关于PowerShell:从压缩文件中提取特定文件/文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43715949/