Reputation: 30906
I'm trying to use Archive::Zip to zip a directory but the resulting zip I get is empty. What am I doing wrong?
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';
}
Upvotes: 2
Views: 1145
Reputation: 9357
Maybe your directory $inDirectory ... is not a directory as expected and I'm not sure but it looks like you don't need the end slash for the 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";
}
Upvotes: 0