Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Very useful -- minor changes are required for use strict and note that on Win32, first filename arg may need to be quoted dependent on shell used...
# zip.pl # Author: Include use strict; use warnings; use Archive::Zip qw( :ERROR_CODES :CONSTANTS ); if ( scalar(@ARGV) < 2 ) { die "Zip.pl\nAuthor:Include\nUsage: zip.pl <c=create, 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"; my $zip = Archive::Zip->new(); die 'Error reading zip file.' if $zip->read($ofile) != AZ_OK; my @members = $zip->members(); foreach my $element (@members) { print "$element\n"; $zip->extractMember($element); } print "Done!\n"; } # create a zip file if ( $opt =~ /c/i ) { print "Zip.pl\nAuthor:Include\n"; print "Creating $ofile...\n"; my $zip = Archive::Zip->new(); foreach my $memberName ( map { glob } @ARGV ) { if ( -d $memberName ) { print "Adding $memberName\n"; warn "Error adding directory $memberName\n" if $zip->addTree( $memberName, $memberName ) != AZ_OK; } else { print "Adding $memberName\n"; $zip->addFile($memberName) or warn "Error adding file $memberName\n"; } } die 'Write error.' if $zip->writeToFileNamed($ofile) != AZ_OK; print "Done!\n"; }

In reply to Re: Create/Extract Zip Archives by msemtd
in thread Create/Extract Zip Archives by #include

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2024-04-16 20:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found