I came across this Powershell blog post about adding folders and files to a zip archive, but it wasn't exactly 100% usable out of the box. Here's a slight re-work of the script that will have you zipping files from a prompt all day and all night:
########################################################
#
# out-zip.ps1
#
# Usage:
#
# To zip up some files:
# ls c:\source\*.txt | out-zip c:\target\archive.zip $_
#
# To zip up a folder:
# gi c:\source | out-zip c:\target\archive.zip $_
########################################################
$path = $args[0]
$files = $input
if (-not $path.EndsWith('.zip')) {$path += '.zip'}
if (-not (test-path $path)) {
set-content $path ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18))
}
$ZipFile = (new-object -com shell.application).NameSpace($path)
$files | foreach {$zipfile.CopyHere($_.fullname)}
Posted
08-07-2006 2:59 PM
by
mhodnick