1
votes

How to write powershell script function to create a zip file excluding .tmp files and bin, obj folder

I tried and found this:

function create-zip([String] $dir, [String] $Zipfile){
    [string]$pathZipExe = "C:\Program Files\7-zip\7z.exe";
    [Array]$arguments = "a", "-tzip", "$Zipfile", "$dir";
    & $pathZipExe $arguments;
}

This code zip all file folder of the source directory but how to exclude .tmp files and "bin", "obj" folders of the source directory from zip

1

1 Answers

3
votes

Try adding these switches to 7Zip's command line:

[Array]$arguments = "a", "-tzip", "$Zipfile", "$dir", "-xr!bin", "-xr!obj", "-xr!*.tmp";