diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2015-07-31 18:59:09 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2015-07-31 18:59:09 +0000 |
commit | 42c8b23669eac442a303190dad44d78cea63cf59 (patch) | |
tree | 1cc49a1a1813bd802988e88058f353a4e0a23514 /examples/zip.pl | |
download | Archive-Zip-tarball-master.tar.gz |
Archive-Zip-1.49HEADArchive-Zip-1.49master
Diffstat (limited to 'examples/zip.pl')
-rw-r--r-- | examples/zip.pl | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/examples/zip.pl b/examples/zip.pl new file mode 100644 index 0000000..a3811d1 --- /dev/null +++ b/examples/zip.pl @@ -0,0 +1,26 @@ +#!/bin/perl -w +# Creates a zip file, adding the given directories and files. +# Usage: +# perl zip.pl zipfile.zip file [...] + +use strict; +use Archive::Zip qw(:ERROR_CODES :CONSTANTS); + +die "usage: $0 zipfile.zip file [...]\n" + if (scalar(@ARGV) < 2); + +my $zipName = shift(@ARGV); +my $zip = Archive::Zip->new(); + +foreach my $memberName (map { glob } @ARGV) { + if (-d $memberName) { + warn "Can't add tree $memberName\n" + if $zip->addTree($memberName, $memberName) != AZ_OK; + } else { + $zip->addFile($memberName) + or warn "Can't add file $memberName\n"; + } +} + +my $status = $zip->writeToFileNamed($zipName); +exit $status; |