user3174311
user3174311

Reputation: 1983

How to add a file to an archive using perl Archive::Zip?

I am using Archive::Zip to create archive files, I'd like to know if I can add a file to an already existing archive? looks like every time I call ->writeToFileNamed the file is truncated...

Upvotes: 2

Views: 2127

Answers (1)

John Doe
John Doe

Reputation: 1138

use strict;
use warnings;
use Archive::Zip;

my $zip = Archive::Zip->new();
#create your archive
my $member = #"file you want to add to archive";
$zip->addMember( $member );

If you don't create your zip inside your script, then just "read" it and add your file...

use warnings;

use strict;

use Archive::Zip qw( :ERROR_CODES );

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

$zip->read('c:\users\user\desktop\test.zip') == AZ_OK or die "read error\n";

$zip->addFile('test.pl');

$zip->overwrite()     == AZ_OK or die "write error\n";

Upvotes: 3

Related Questions