Thursday, June 19, 2008

Perl script to display the content of a zip file

Here is a little script that shows the number of files in a zip file and the names of the files. Interesting thing is that, we don't need to unzip the file.

Here is the code

use Archive::Zip qw( :ERROR_CODES :CONSTANTS );

my $zip = Archive::Zip->new();

my $zip_file_name = 'scraper.zip';

$zip->read( $zip_file_name );

print "Number of files in the zip file: ".$zip->numberOfMembers()."\n";
print "List of files:\n";

my @members = $zip->memberNames();

#now print the name of the files
foreach (@members)
{
print $_, "\n";
}


For details, please check http://search.cpan.org/~adamk/Archive-Zip-1.23/lib/Archive/Zip.pm

No comments: