PS C:\testing\powershell\testfiles> foreach($dir in (Get-ChildItem .)) {
cd $dir.fullname
Write-Zip .\*.tif "$($dir.Name).zip"
}This example assumes PSCX is imported. As it loops through the subdirectories it looks for files matching the extension, in this case, *.tif, and copies them to a .zip file named after the current directory. For my production example this works perfectly as I named the folders sequentially to indicate the project and data set I was working on. Unfortunately, the original switch that allowed you to remove the original is not an option any longer. Nonetheless, I can accomplish the same thing after I run the previous command with one more line:dir .\*.tif | Remove-ItemI had thought about running jobs to accelerate the process, but, wanted to really be sure this works as intended before I add another layer of complication/abstraction.In my first actual production run I found I was zipping 1000 files in 14 seconds every time. Using my own concoction, not only did I have corrupted zips, if the process got interrupted, but, it took much, much longer (read hours). This way I might be able to finish my work in 1/20th of the time it took me before. Thank you again Powershell and PSCX crew.
0 comments:
Post a Comment