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

Re: Create/Extract Zip Archives

by msemtd (Scribe)
on Jun 03, 2003 at 13:58 UTC ( [id://262655]=note: print w/replies, xml ) Need Help??


in reply to Create/Extract Zip Archives

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"; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://262655]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2024-04-24 18:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found