Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

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 "Zip.pl\nAuthor:Include\nUsage: zip.pl <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 "Zip.pl\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:
$ ./ziptest.pl X zipbatch/testzip.zip testout.txt
Zip.pl
Author:Include
Extracting zipbatch/testzip.zip...
Archive::Zip::ZipFileMember=HASH(0x1e68844)
Archive::Zip::ZipFileMember=HASH(0x1e68e14)
Archive::Zip::ZipFileMember=HASH(0x1e68fe4)
Archive::Zip::ZipFileMember=HASH(0x1a4890c)
Done!

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

Thank you!

Comment on Listing contents and stats of ZIP archive contents
Download Code
Re: Listing contents and stats of ZIP archive contents
by LanX (Canon) 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)

Re: Listing contents and stats of ZIP archive contents
by ww (Bishop) 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 (Abbot) 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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1033361]
Approved by sundialsvc4
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (18)
As of 2014-07-10 19:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (215 votes), past polls