ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> perl-win32-users
perl-win32-users
Re: Archive::Zip problem
by Sisyphus other posts by this author
Jul 1 2009 11:07PM messages near this date
view in the new Beta List Site
Archive::Zip problem | Re: Archive::Zip problem
----- Original Message ----- 
From: "Kprasad" <kprasad@[...].com> 

#!/usr/bin/perl
use Archive::Zip qw( :ERROR_CODES :CONSTANTS );   # imports
#mkdir "c:/onfly";
my $localdir="c:/onfly"; ## I've two zip files i.e., first.zip and 
second.zip which respectively contains 3 files and two files and after 
extraction 'c:/onfly/first' should contain 3 files and c:/onfly/second' 
should contain 2 files only

 $obj = Archive::Zip-> new();   # new instance

    opendir(DIR, $localdir) || print "\nerror\n";
    my @zipfiles=grep /$ARGV[0].*\.zip/, readdir(DIR);
    close(DIR);
    foreach $zipfiles (@zipfiles)
    {
     if($obj-> read("$localdir/$zipfiles") == AZ_OK)  # read file contents
     {
      print "$zipfiles\n";
      $unzip=substr($zipfiles,0,length($zipfiles)-4);
      print "$unzip\n";
      if($obj-> extractTree(undef, "$localdir/$unzip/")){print "Extracting 
$zipfiles";}}
     else{die('Error in file!');}
    }

#################################################
#################################################

Maybe you just need to create a different Archive::Zip object for each zip 
file. Something like (untested):

use warnings;
use strict;
use Archive::Zip qw( :ERROR_CODES :CONSTANTS );   # imports
#mkdir "c:/onfly";
my $localdir="c:/onfly";

    opendir(DIR, $localdir) || print "\nerror\n";
    my @zipfiles=grep /$ARGV[0].*\.zip/, readdir(DIR);
    close(DIR);
    foreach $zipfiles (@zipfiles)
    {
     my  $obj = Archive::Zip-> new();   # new instance
     if($obj-> read("$localdir/$zipfiles") == AZ_OK)  # read file contents
     {
      print "$zipfiles\n";
      $unzip=substr($zipfiles,0,length($zipfiles)-4);
      print "$unzip\n";
      if($obj-> extractTree(undef, "$localdir/$unzip/")){print "Extracting 
$zipfiles";}}
     else{die('Error in file!');}
    }

__END__

I saw this near the end of the Archive::Zip documentation:

## quote ##
  When not to use Archive::Zip
    If you are just going to be extracting zips (and/or other archives) you
    are recommended to look at using Archive::Extract instead, as it is much
    easier to use and factors out archive-specific functionality.
## end quote ##

Cheers,
Rob

_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@[...].com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Thread:
Kprasad
Sisyphus
Chris Wagner

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved