Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Listing contents and stats of ZIP archive contents

by cbullard (Initiate)
on May 13, 2013 at 21:40 UTC ( #1033361=perlquestion: print w/replies, xml ) Need Help??
cbullard has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to list out the names and stats of the contents of a ZIP file. I've tried working with both Archive::Extract and IO::Uncompress with no success. I've even tried using this code straight from the PerlMonks Archives:

#! c:\perl\bin\perl use Archive::Zip qw( :ERROR_CODES :CONSTANTS ); if (scalar(@ARGV) < 2){die "\nAuthor:Include\nUsage: <c=c +reate, x=extract> <filename> <files>\n";}; my $opt = shift(@ARGV); my $ofile = shift(@ARGV); # extract a zip file if($opt=~/x/i){ print "\nAuthor:Include\n"; print "Extracting $ofile...\n"; $zip = Archive::Zip->new(); die 'Error reading zip file.' if $zip->read( $ofile ) != AZ_OK; my @members = $zip->members(); foreach $element(@members) { print "$element\n"; $zip->extractMember($element); } print "Done!\n"; }

but all I get for output is:
$ ./ X zipbatch/ testout.txt
Extracting zipbatch/

How can I access the list of files inside the zip archive and the stats for them (size, mod date, etc)?

Thank you!

Replies are listed 'Best First'.
Re: Listing contents and stats of ZIP archive contents
by ww (Archbishop) on May 13, 2013 at 22:22 UTC
    The output you show means you're printing a hashref rather than a simple array element. See "References" in the Tutorials Section here for guidance on how to print the hash pointed to by the hashref.

    You may also profit by carefully reading the documentation of Archive::Zip for related info.

    If you didn't program your executable by toggling in binary, it wasn't really programming!

Re: Listing contents and stats of ZIP archive contents
by NetWallah (Canon) on May 14, 2013 at 04:10 UTC
    You probably need:
    print $element->fileName(), " Mod Time: " . scalar( localtime( $eleme +nt->lastModTime() ) ), " Size=" . $element->uncompressedSize() , "\n";

                 "I'm fairly sure if they took porn off the Internet, there'd only be one website left, and it'd be called 'Bring Back the Porn!'"
            -- Dr. Cox, Scrubs

Re: Listing contents and stats of ZIP archive contents
by LanX (Bishop) on May 13, 2013 at 22:00 UTC
    Your posting seems to be wrapped within the signature div.

    It's barely readable...better correct it!

    Cheers Rolf

    ( addicted to the Perl Programming Language)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1033361]
Approved by sundialsvc4
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2018-05-25 21:45 GMT
Find Nodes?
    Voting Booth?