【问题标题】:How to add a file to an archive using perl Archive::Zip?如何使用 perl Archive::Zip 将文件添加到存档中?
【发布时间】:2016-08-25 16:49:25
【问题描述】:

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

【问题讨论】:

  • 看看这个link,它可能有你需要的东西。
  • 也可以使用$zip->addMember( $member )

标签: perl zip archive


【解决方案1】:
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,那么只需“读取”它并添加您的文件...

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

【讨论】:

  • 对不起,如果我不够清楚,我想将文件添加到现有的 zip 文件中。
  • 好的,我为第二种情况添加了解决方案,如果它确实解决了您的问题,请接受它作为答案
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-07
  • 1970-01-01
  • 1970-01-01
  • 2014-04-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多