I need to download a zip file and extract the contents as part of a batch process, with some fine grain control over the name and location of the extracted file.
Never messed with zip files using Perl before, so here is the first step - a very simple example to extract the contents of a zip file to the current directory using the names in the zip file.
There is an excellent FAQ and lots of good examples in the distribution.
#!/usr/bin/perl
# extract_zip.pl - very simple zip extract example
use strict;
use warnings;
use Archive::Zip qw( :ERROR_CODES :CONSTANTS );
my $zip_name = "example.zip";
my $zip = Archive::Zip->new($zip_name);
unless (defined $zip) {
die "Unable to open $zip_name\n";
}
print "The zip file contains ", $zip->numberOfMembers(), " members:\n";
for my $member_name ($zip->memberNames()) {
print " Extracting $member_name\n";
my $status = $zip->extractMemberWithoutPaths($member_name);
die "\nExtracting $member_name from $zip_name failed\n" if $status != AZ_OK;
}
exit 1;
