7zip - powershell exclude files/folders with variable
我正在尝试压缩文件夹,但使用powershell排除多个目录。
我得到了以下内容:
1 2 3 4 5 6 7 8 | if (-not (test-path"$env:ProgramFiles\\7-Zip\\7z.exe")) {throw"$env:ProgramFiles\\7-Zip\\7z.exe needed"} set-alias sz"$env:ProgramFiles\\7-Zip\\7z.exe" $Source ="D:\\Zip\\*" $Target ="D:\\backup.7z" $exclude = 'Customer\\Images\\*' sz a -xr!'$Customer\\Images\\*' $Target $Source |
这很好。.但是当我想要将
尝试一下...
1 2 3 4 5 6 7 8 9 10 11 12 13 | if (-not (Test-Path"$env:ProgramFiles\\7-Zip\\7z.exe")) {throw"$env:ProgramFiles\\7-Zip\\7z.exe needed"} $7ZipPath ="$env:ProgramFiles\\7-Zip\\7z.exe" $Source ="D:\\Zip\\*" $Target ="D:\\backup.7z" $foldersToExclude = 'folder1', 'folder2' $7zipParams = @('a',$Target) @($foldersToExclude) | ForEach-Object { $7zipParams +="`"-xr!$_`"" } $7zipParams += $Source Write-Host ($7ZipPath+' '+$7zipParams -join ' ') # debug - show the command line &$7ZipPath $7zipParams |
我们创建了一组参数以传递到7zip中,包括排除的文件夹。在添加排除的文件夹时,我们在文件夹名称前添加
我通过使用7zip可执行文件创建一个字符串,然后在该字符串路径前加一个&符来调用7zip,与您稍有不同。
此方法可以从最终归档中排除多个文件夹,包括
两件事: