当我像这样压缩归档文件时,我可以以某种方式排除文件夹吗?
$compress = Compress-Archive $DestinationPath $DestinationPath\ARCHIVE\archiv-$DateTime.zip -CompressionLevel Fastest现在,它总是将$destinationpath的整个文件夹结构保存到归档中,但是由于归档位于同一文件夹中,因此总是将其压缩到一个新的归档中,每次我运行该命令时,都会使归档的大小加倍。
发布于 2016-12-11 17:12:04
您可以使用Compress-Archive的-update选项。使用Get-ChildItem和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发布于 2016-12-11 21:21:28
获取要压缩的所有文件,不包括不想压缩的文件和文件夹,然后将其传递给cmdlet
# 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 Fastesthttps://stackoverflow.com/questions/41081488
复制相似问题