PowerShell:从压缩文件中提取特定文件/文件夹

标签 powershell zip archive unzip

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/

相关文章:

utf-8 - Zip 存档注释使用什么编码?

c# - .NET Windows 资源管理器扩展来浏览 .zip 之类的文件?

powershell - 如何更改 PowerShell 中路径的中间项?

java - 在哪里可以了解 Java 中的文本压缩?

java - 将大型 CSV 流写入内存中的 ZipOutputStream 消耗的内存是否与 CSV 或潜在 zip 的大小一样多?

deployment - 是否有支持现代多线程归档程序的任务 - 7zip、winrar 等?

powershell - 新-AzureReservedIP : What´s the difference between ReservedIPName and Label?

visual-studio-2010 - PowerShell CmdLe 作为 Visual Studio 外部工具

powershell - 使用 Powershell 将 EBS 卷附加到 Windows EC2

java - 我的 Java 程序如何在其 .jar 文件中存储文件?