PowerShell:从压缩的存档中提取特定的文件/文件夹 [英] PowerShell: Extract specific files/folders from a zipped archive

查看:0
本文介绍了PowerShell:从压缩的存档中提取特定的文件/文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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:	empmyzipdir.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:	empc" -Force

#extraction
$entries | foreach {[IO.Compression.ZipFileExtensions]::ExtractToFile( $_, "c:	empc" + $_.Name) }

#free object
$zip.Dispose()

这篇关于PowerShell:从压缩的存档中提取特定的文件/文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆