perl zip目录为空

时间:2011-06-25 01:19:44

标签: perl

我正在尝试使用Archive :: Zip来压缩目录,但我得到的结果是空的。 我做错了什么?

   my ($inDirectory, $outFile) = @_;

   # Create a Zip file
   my $zip = Archive::Zip->new();

   # Add a directory
   my $dir_member = $zip->addDirectory($inDirectory. "/");

   # Save the Zip file
   unless ( $zip->writeToFileNamed($outFile) == AZ_OK ) {
       die 'Could not zip file';
   }

2 个答案:

答案 0 :(得分:3)

搞定了,我不得不使用$ zip-> addTree

答案 1 :(得分:0)

也许您的目录 $ inDirectory ...不是预期的目录,我不确定但看起来您不需要dirname的结束斜杠:

print $inDirectory::Find::name;
if ( -d $inDirectory::Find::name ) { # just grab directories, not files.
   print "adding a dir\n";
   $zip->addDirectory($inDirectory::Find::name);
} else {
  #zip files
   print "adding a file\n";
  $zip->addFile($inDirectory::Find::name) != AZ_OK ||  print "couldn't add file \n";
}