1 Replies - 1916 Views - Last Post: 13 September 2009 - 02:34 PM

#1 born2c0de   User is offline

  • printf("I'm a %XR",195936478);
  • member icon

Reputation: 187
  • View blog
  • Posts: 4,673
  • Joined: 26-November 04

Using ZIP Files with PERL

Posted 27 February 2005 - 03:39 AM

Description: This code creates and Extracts ZIP Files. ORIGINALLY WRITTEN BY: Wraithnix
# zip.pl
# Author: Wraithnix
use Archive::Zip qw( :ERROR_CODES :CONSTANTS );

if (scalar(@ARGV) < 2){die "Zip.plnAuthor:WraithnixnUsage: zip.pl   n";};

my $opt = shift(@ARGV);
my $ofile = shift(@ARGV);

# extract a zip file
if($opt=~/x/i){
print "Zip.plnAuthor:Wraithnixn";
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 "$elementn";
  $zip->extractMember($element);
}
print "Done!n";
}

# create a zip file
if($opt=~/c/i){
print "Zip.plnAuthor:Wraithnixn";
print "Creating $ofile...n";
my $zip = Archive::Zip->new();
foreach my $memberName (map { glob } @ARGV)
{
     if (-d $memberName )
     {
    print "Adding $memberNamen";
          warn "Error adding directory $memberNamen"
               if $zip->addTree( $memberName, $memberName ) != AZ_OK;
     }
     else
     {
    print "Adding $memberNamen";
          $zip->addFile( $memberName )
               or warn "Error adding file $memberNamen";
     }
}
die 'Write error.' if $zip->writeToFileNamed( $ofile ) != AZ_OK;
print "Done!n";
}
 



Is This A Good Question/Topic? 0
  • +

Replies To: Using ZIP Files with PERL

#2 nathanpc   User is offline

  • SCIENCE!
  • member icon

Reputation: 113
  • View blog
  • Posts: 1,171
  • Joined: 31-July 09

Re: Using ZIP Files with PERL

Posted 13 September 2009 - 02:34 PM

Very nice!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1