## Command Line Zip for Windows

Windows doesn't have a command line utility for compressing files (that I know of), and I had to come up with a way to automate some file transfers today. So I whipped up a tiny Perl script that will zip up a file. I figure someone else might need it. (Or someone might know how to do this in one line.) You'll need the Archive::Zip module, and the following code—which is pretty much right out of the documentation:
 # Grab the incoming file my $argv = join(' ', @ARGV) or die "Usage: zipme.pl [file location]\n"; # Grab the file name my($dir, $file) =$argv =~ m/(.*\\)(.*)$/; # Create a Zip file use Archive::Zip qw( :ERROR_CODES :CONSTANTS ); my$zip = Archive::Zip->new(); # Add the file my $file_member =$zip->addFile($argv,$file); # Save the Zip file unless ( $zip->writeToFileNamed($argv.'.zip') == AZ_OK ) {     die 'couldn\'t zip'; } 
Save this code as zipme.pl, and you'll be set. Pass in a filename, and you'll get a compressed file of the same name plus the .zip extension. So:

C:\>perl zipme.pl C:\path\to\giant.file

will give you C:\path\to\giant.file.zip. It works well with Windows batch files, and will save me a bunch of bandwidth.

perl -MArchive::Zip -e "qq(@ARGV) =~ m/(.*[\\\/])?(.*)$/ && ($_ = Archive::Zip->new) && $_->addFile(qq(@ARGV),$2) && \$_->writeToFileNamed(qq(@ARGV.zip)) && die qq(couldn't zip)" %1 %2 %3 %4 %5 %6 %7 %8 %9