如何使用 perl Archive::Zip 将文件添加到存档?

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

我正在使用 Archive::Zip 创建归档文件,我想知道我是否可以将文件添加到已经存在的归档中?看起来每次我调用 ->writeToFileNamed 文件都会被截断...

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 );

如果您不在脚本中创建 zip,那么只需"read"它并添加您的文件...

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";