SOLVED (Scroll down for solution)

I have some zip files.

my @filelist = ('zip1.zip','zip2.zip','zip3.zip');

Let's say that the contents of the zip files look like this:

zip1.zip -->file1.txt -->file2.txt zip2.zip -->directory1 (dir) ---->file1.txt ---->file3.txt -->file4.txt zip3.zp -->file5.txt -->file6.txt -->file7.txt

I wish to dynamically create a zip file called bigzip.zip that will include the contents of the zip files as a sub-directory in bigzip.zip. In other words, I want this:

bigzip.zip -->zip1 (dir) ---->file1.txt ---->file2.txt -->zip2 (dir) ---->directory1 (dir) ------>file1.txt ------>file3.txt ---->file4.txt -->zip3 (dir) ---->file5.txt ---->file6.txt ---->file7.txt

Here's the code I have so far:

my $zip = Archive::Zip->new(); foreach (@filelist) { my $file = Archive::Zip->new($_}); foreach ($file->members()){ $zip->addMember( $_ ); } }

This successfully results in:

bigzip.zip -->file1.txt -->file2.txt -->directory1 (dir) ---->file1.txt ---->file3.txt -->file4.txt -->file5.txt -->file6.txt -->file7.txt

I can't figure out from the documentation if what I'm talking about is at all possible, and how to achieve it. I could, of course, extract the individual zips into the directories I want, then re-zip them, but that seems inelegant.

Any thoughts?

Solved: The following code works. I didn't realize that "directories" in zip files were simply a matter of specifying paths...

my $x=1; my $zip = Archive::Zip->new(); foreach (@filelist) { my $file = Archive::Zip->new($_); my $directoryname = 'zip'.$x; foreach ($file->members()){ my $m = $zip->addMember( $_ ); $m->fileName($directoryname.'/'.$m->fileName()); } $x++; }

In reply to Archive::Zip: add members of one archive to sub-directory in another archive by tunafish

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.