Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Can I list contents of nested zipfile using Archive::Zip withoutextracting the outermost zip?

Reply
Thread Tools

Can I list contents of nested zipfile using Archive::Zip withoutextracting the outermost zip?

 
 
Graham Wood
Guest
Posts: n/a
 
      01-09-2004
I need to check the structure of a nested zipfile and I'm wondering if
it is possible to do this using Archive::Zip without having to extract
the contents of the outermost zipfile into a temporary directory.

The structure of the zipfile is:

1233456.zip
123456_ar.zip
123456/abcdef/xy/help/US/file1.htm
123456/abcdef/xy/help/US/file2.htm
123456/abcdef/xy/help/US/file3.htm
123456_bg.zip
123456_ce.zip


I want to do this:
1 open the 123456.zip
read the filename.zip list (I've got this far!)
foreach filename.zip (eg 123456_ar.zip)
list the contents of the filename.zip
}
}

Can I get there without extracting 1233456.zip first?

Thanks in advance

Graham

 
Reply With Quote
 
 
 
 
A. Sinan Unur
Guest
Posts: n/a
 
      01-09-2004
Graham Wood <(E-Mail Removed)> wrote in news:LUBLb.4
$(E-Mail Removed):

> I want to do this:
> 1 open the 123456.zip
> read the filename.zip list (I've got this far!)
> foreach filename.zip (eg 123456_ar.zip)
> list the contents of the filename.zip
> }
> }
>
> Can I get there without extracting 1233456.zip first?


Have you looked at the docs?

http://search.cpan.org/~nedkonz/Archive-Zip-
1.09/lib/Archive/Zip.pod#Zip_Archive_Accessors

(URL wrapped in newsreader)

#! perl

use strict;
use warnings;

use Archive::ZIP qw( :ERROR_CODES :CONSTANTS );

my $zip = Archive::Zip->new('test.zip');

print map { "$_\n" } $zip->memberNames();

__END__



--
A. Sinan Unur
http://www.velocityreviews.com/forums/(E-Mail Removed) (reverse each component for email address)
 
Reply With Quote
 
 
 
 
Graham Wood
Guest
Posts: n/a
 
      01-10-2004
A. Sinan Unur wrote:
> Graham Wood <(E-Mail Removed)> wrote in news:LUBLb.4
> $(E-Mail Removed):
>
>
>>I want to do this:
>>1 open the 123456.zip
>> read the filename.zip list (I've got this far!)
>> foreach filename.zip (eg 123456_ar.zip)
>> list the contents of the filename.zip
>> }
>>}
>>
>>Can I get there without extracting 1233456.zip first?

>
>
> Have you looked at the docs?
>
> http://search.cpan.org/~nedkonz/Archive-Zip-
> 1.09/lib/Archive/Zip.pod#Zip_Archive_Accessors
>

Yes, that's how I "got this far" already.

> (URL wrapped in newsreader)
>
> #! perl
>
> use strict;
> use warnings;
>
> use Archive::ZIP qw( :ERROR_CODES :CONSTANTS );
>
> my $zip = Archive::Zip->new('test.zip');
>
> print map { "$_\n" } $zip->memberNames();


This will list the members in the first zipfile. However, all the
members of the first zipfile are themselves zipfiles as well. I'm
trying to find out how to call $zip->memberNames() on each member inside
the first zipfile.

I could just extract the first zipfile, then open each individual zip
that came out of it but I was hoping there was some way of doing the
whole thing in memory.

Graham

 
Reply With Quote
 
A. Sinan Unur
Guest
Posts: n/a
 
      01-11-2004
Graham Wood <(E-Mail Removed)> wrote in news:3FFFF821.8020606
@oracle.com:

> A. Sinan Unur wrote:
>> Graham Wood <(E-Mail Removed)> wrote in news:LUBLb.4
>> $(E-Mail Removed):
>>
>>
>>>I want to do this:
>>>1 open the 123456.zip
>>> read the filename.zip list (I've got this far!)
>>> foreach filename.zip (eg 123456_ar.zip)
>>> list the contents of the filename.zip
>>> }
>>>}
>>>
>>>Can I get there without extracting 1233456.zip first?

>>
>>
>> Have you looked at the docs?

....
> Yes, that's how I "got this far" already.


Fair enough. Sorry I misunderstood your question.

I am not familiar with the Archive::Zip module, but the following script
I cobbled together based on one of the examples seems to work. At first I
thought Archive::Zip::MemberRead would do the job but I ran into some
difficulties.

Here are the contents of the two zip files I used:

C:\Home> unzip -l test1.zip
Archive: test1.zip
Length Date Time Name
-------- ---- ---- ----
2040 01-10-04 20:13 test.zip
-------- -------
2040 1 file

C:\Home> unzip -l test.zip
Archive: test.zip
Length Date Time Name
-------- ---- ---- ----
398 12-04-03 23:13 dload/misc/ddd.pl
793 11-08-03 10:30 dload/misc/g.pl
1460 07-23-03 10:47 dload/misc/r.pl
940 07-23-03 23:40 dload/misc/s.pl
-------- -------
3591 4 files

Here is the script (no error checking):

C:\Home> cat t.pl
#! perl

use strict;
use warnings;

use Archive::Zip qw( :ERROR_CODES :CONSTANTS );
use IO::Scalar;

my $zip = Archive::Zip->new('test1.zip');
my $member = $zip->memberNamed('test.zip');
my $member_contents = $member->contents();
my $member_contents_sh = IO::Scalar->new(\$member_contents);
my $member_zip = Archive::Zip->new();
$member_zip->readFromFileHandle($member_contents_sh);
print map { "$_\n" } $member_zip->memberNames();

__END__

C:\Home> t.pl
dload/misc/ddd.pl
dload/misc/g.pl
dload/misc/r.pl
dload/misc/s.pl

HTH.

Sinan.

--
A. Sinan Unur
(E-Mail Removed) (reverse each component for email address)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
newbie question: nested archives and zipfile gilbeert@gmail.com Python 1 02-01-2007 01:22 PM
Re: It seems that ZipFile().write() can only write files,how can empty directories be put into it? Jeff Epler Python 0 07-01-2005 02:06 PM
It seems that ZipFile().write() can only write files,how can empty directories be put into it? could ildg Python 0 07-01-2005 01:50 AM
explaination need for if such a qualifier appears at the outermost level of the parameter type, it is simply ignored: baumann@pan C++ 0 05-19-2005 07:08 AM
RegExp outermost () Chris Morris Ruby 1 07-22-2003 06:54 PM



Advertisments