user3174311 user3174311 - 1 year ago 149
Perl Question

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...

Answer Source
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\') == AZ_OK or die "read error\n";


$zip->overwrite()     == AZ_OK or die "write error\n";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download