如何使用powershell和7zip ( 7za.exe )压缩文件夹,同时排除某些文件类型?
我试过这个:
cd "C:\path\to\folder to zip"
7za.exe a "C:\path\to\newZip.zip" -mx3 -x!*.txt -x!*.pdf但这会得到回报:
.txt: WARNING: The system cannot find the file specified.
.pdf: WARNING: The system cannot find the file specified.并且没有压缩任何东西--只是创建了一个空的ZIP文件。
我也尝试过这个:
cd "C:\path\to\folder to zip"
Get-ChildItem "C:\path\to\folder to zip" -Recurse -Exclude *.txt, *.pdf | 7za.exe a -mx3 "C:\path\to\newZip.zip" $_.FullName但这会将"C:\path\ to \folder to zip“文件夹中的所有内容压缩到zip文件夹中,而不是排除任何内容。
感谢您能提供的任何帮助。
-Jim
发布于 2012-02-24 02:11:35
您的第二次尝试几乎是正确的。
调用7-zip的命令需要包装在一个for-each块中,否则$_.FullName将解析为一个空字符串,并且7-zip (在没有输入参数的情况下)会自动压缩目录中的所有内容。因此,将其更改为:
Get-ChildItem "C:\path\to\folder to zip" -Recurse -Exclude *.txt, *.pdf | %{7za.exe a -mx3 "C:\path\to\newZip.zip" $_.FullName}请注意,%是foreach-object的别名。
https://stackoverflow.com/questions/9416402
复制相似问题