如何排除压缩存档中的文件夹 [英] How do I exclude a folder in compress-archive

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

问题描述

当我压缩这样的档案时,我可以以某种方式排除文件夹吗?

Can I somehow exclude a folder when I compress an archive like this?

$compress = Compress-Archive $DestinationPath $DestinationPath\ARCHIVE\archiv-$DateTime.zip -CompressionLevel Fastest

现在它总是将 $destinationpath 的整个文件夹结构保存到存档中,但由于存档在同一个文件夹中,它总是被压缩到一个新的存档中,使存档的大小翻倍每次我运行命令.

Now it always saves the whole folder structure of $destinationpath to the archive, but since the archive is in the same folder, it always gets zipped into a new archive, making the archive double in size every time I run the command.

推荐答案

您可以使用 Compress-Archive 的 -update 选项.使用 Get-ChildItem 和 Where

you can use -update option of Compress-Archive. Select your subdirs with Get-ChildItem and Where

喜欢:

$YourDirToCompress="c:\temp"
$ZipFileResult="C:\temp10\result.zip"
$DirToExclude=@("test", "test1", "test2")

Get-ChildItem $YourDirToCompress -Directory  | 
           where { $_.Name -notin $DirToExclude} | 
              Compress-Archive -DestinationPath $ZipFileResult -Update

这篇关于如何排除压缩存档中的文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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