Reputation: 11755
I have two zip files, A.zip
and B.zip
. I want to add whatever files are in A.zip
to B.zip
.
How can I do this with Archive::Zip
in Perl? I thought I could do something like this:
my $zipA = Archive::Zip->new();
my $zipB = Archive::Zip->new();
die 'read error' unless ($zipA->read( 'A.zip' ) == AZ_OK );
my @members = $zipA->memberNames();
for my $m (@members) {
my $file = $zipA->removeMember($m);
$zipB->addMember($file);
}
but unless I call writeToFileNamed()
then no files get created, and if I do call it, B.zip
gets overwritten with the contents of A.zip
.
I could read in the contents of B.zip
, and write them along with the contents of A.zip
back to B.zip
but this seems really inefficient. (My problem actually involves millions of text files compressed into thousands of zip files.)
Is there a better way to do this?
Upvotes: 1
Views: 987
Reputation: 6798
Using Archive::Zip
:
my $zipA = Archive::Zip->new('A.zip');
my $zipB = Archive::Zip->new('B.zip');
foreach ($zipA->members) {
$zipA->removeMember($_);
$zipB->addMember($_);
}
$zipB->overwrite;
The problem is:
(I'll leave it to you to do error handling etc)
Upvotes: 2
Reputation: 344
You may try chilkat::CkZip
instead of Archive::Zip
. Its QuickAppend()
method seems to be helpful.
Upvotes: 0