powershell - Powershell - 根据另一个 zip 文件的内容压缩文件
问题描述
我有一个必须解压缩到目标文件夹的 zip 文件。在我提取之前,我只想备份根文件和将通过提取 zip 文件替换的子目录。
我可以编写一个脚本来找出 .zip 中的子目录并从目标文件夹中备份这些子目录(如果它们可用)?
我将在 Azure DevOps 中使用这个脚本。
解决方案
您可以使用 PowerShell 发现 zip 文件内容,检查它是否存在于目标文件夹中,如果存在 - 进行备份。例如:
$ZipFilePath = "C:\Users\sabramczyk\Documents\Scrum.zip"
$DestinationFolder = "c:\test"
Add-Type -assembly "System.IO.Compression.FileSystem"
if (![System.IO.File]::Exists($ZipFilePath)) {
throw "Zip file ""$ZipFilePath"" not found."
}
$ZipContent = ([System.IO.Compression.ZipFile]::OpenRead($ZipFilePath)).Entries.FullName
foreach($zipContent in $ZipContent)
{
if(Test-Path $DestinationFolder+"/"+$zipContent)
{
# Do backup
}
}
推荐阅读
- computer-vision - 用火炬平均计算阿尔法值?
- php - 如何解析类似于 .ini 文件的格式化文本?
- java - 生成二维码后如何保存名称
- python - 如何使用 pandas 和 python 从网站中提取和保存特定选项卡中显示的表格?
- javascript - 你如何让眼睛移动并跟随光标?老实说,我不知道从这里做什么
- r - 查找数据中的突然斜率
- react-native - 如何在反应本机屏幕上“锁定”组件的位置?
- java - Firestore 中的 WhereNotEqualTo 不起作用,但 whereEqualTo 起作用
- python - 合并多个 Pandas Dataframe 对象
- excel - Excel 中的范围与 Google 表格中的范围