2
我想创建PowerShell脚本功能来压缩文件夹,这里不包括一些文件夹和文件是我的代码,其中创建压缩文件,包括所有文件和文件夹PowerShell脚本 - 创建zip文件排除某些文件和文件夹
# Zip creator method
function create-zip([String] $aDirectory, [String] $aZipfile){
[string]$pathToZipExe = "C:\Program Files\7-zip\7z.exe";
[Array]$arguments = "a", "-tzip", "$aZipfile", "$aDirectory";
& $pathToZipExe $arguments;
}
但我想排除* .tmp文件和bin和OBJ文件夹
我发现Get-ChildItem "C:\path\to\folder to zip" -Recurse -Exclude *.txt, *.pdf | %{7za.exe a -mx3 "C:\path\to\newZip.zip" $_.FullName}
工作正常的PowerShell命令,但如何使用它在脚本文件的功能
PLZ建议...
快一个 - 你在哪里放置这些函数实际上是为了让powershell可以访问它们 – pal4life
你可以将上面的函数放在profile.ps1脚本中(位于$ home \ Documents \ WIndowsPowerShell下)。 PowerShell将在加载该脚本时处理该脚本,并且该功能将可用。 –