首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何排除压缩存档中的文件夹

如何排除压缩存档中的文件夹
EN

Stack Overflow用户
提问于 2016-12-11 07:40:22
回答 2查看 16.5K关注 0票数 17

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

代码语言:javascript
运行
复制
$compress = Compress-Archive $DestinationPath $DestinationPath\ARCHIVE\archiv-$DateTime.zip -CompressionLevel Fastest

现在,它总是将$destinationpath的整个文件夹结构保存到归档中,但是由于归档位于同一文件夹中,因此总是将其压缩到一个新的归档中,每次我运行该命令时,都会使归档的大小加倍。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-12-11 17:12:04

您可以使用Compress-Archive的-update选项。使用Get-ChildItem和Where选择子目录

喜欢:

代码语言:javascript
运行
复制
$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
票数 18
EN

Stack Overflow用户

发布于 2016-12-11 21:21:28

获取要压缩的所有文件,不包括不想压缩的文件和文件夹,然后将其传递给cmdlet

代码语言:javascript
运行
复制
# target path
$path = "C:\temp"
# construct archive path
$DateTime = (Get-Date -Format "yyyyMMddHHmmss")
$destination = Join-Path $path "ARCHIVE\archive-$DateTime.zip"
# exclusion rules. Can use wild cards (*)
$exclude = @("_*.config","ARCHIVE","*.zip")
# get files to compress using exclusion filer
$files = Get-ChildItem -Path $path -Exclude $exclude
# compress
Compress-Archive -Path $files -DestinationPath $destination -CompressionLevel Fastest
票数 22
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41081488

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档