Last active
February 7, 2020 16:31
-
-
Save JohnL4/4bd8fd056fdf41ca0eb55580192c9c0a to your computer and use it in GitHub Desktop.
PowerShell cmd to zip up a directory while excluding multiple subdirectories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ls -rec | ? {-not ($_.FullName -match '\\(NUnitConsole|TestRun)\\')} | write-zip -output "$(datefn).zip" | |
#### If you want to get fancier... | |
# (1) Make a list of files touched in the last hour. | |
$fs = ls c:\work\sxa\18.4cu2\Projects\VisitRecord\VRDotNet\Portal\SXA.VR.Portal\bin ` | |
| ? {$_.LastWriteTime -ge (Get-Date).AddMinutes(-60)} | |
# (2) Add to it. The '+=' operator actually makes a new Array by copying the old Array + the entry(ies). | |
# This is how you get another file, even if it wasn't touched in the last hour. | |
$fs += (ls c:\work\sxa\18.4cu2\Projects\VisitRecord\VRDotNet\Portal\SXA.VR.Portal\Views\Home\Index.cshtml) | |
# (3) Zip it all up, sans directory structure. Write-Zip is from PSCX. Sadly, its -Append option seems to be broken, | |
# so we have to build our list BEFORE we write the zip file. Oh well, good learning list-management skillz. :) | |
pushd c:/tmp | |
$fs | write-zip -out web-server-dlls.zip -flat -entry / |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Apparently, the -exclude option is borked, so we do it with regular expressions.
'datefn' is a function that returns a string timestamp suitable for use as a filename.