如何使用共享相同名称的多个文件创建zip文件

时间:2013-09-11 02:20:23

标签: perl zip 7zip

任何人都可以帮我创建两个同名文件的zip文件。这是出于测试目的之一。如果您有任何zip文件包含相同的文件,如a.txt和a.txt作为内容,请告诉我。任何帮助都非常感谢。

1 个答案:

答案 0 :(得分:2)

使用Archive::Zip实际上很容易。

my $zip = Archive::Zip->new;
$zip->addString("test one", "a.txt");
$zip->addString("test two", "a.txt");
$zip->writeToFileNamed("test.zip");

尝试使用标准解压缩工具提取它时,没有什么比这更有趣了:

$ unzip test.zip
Archive:  test.zip
 extracting: a.txt
replace a.txt? [y]es, [n]o, [A]ll, [N]one, [r]ename: y
 extracting: a.txt

如果您更喜欢稍微有趣的内容,当然可以使用addFile方法代替addString

相关问题