in reply to Problems with Archive::zip

Actually you misunderstood how this module works.

addDirectory method is not for adding an actual directory you currently have, it's just to sort things out inside your zip file

For example:

$zip->addDirectory('something'); $zip->writeToFileNamed('test.zip');

Would create a zip file that contain a directory named 'something' and it doesn't to exists in your system to be added to the zip file.

Add file should have added the file in question and I have to idea why it's failing for you ... again you can use it to sort things inside your zip file

For example

$zip->addDirectory('something'); $zip->addFile('C:\somefile.pl', 'something/better_name.pl'); $zip->writeToFileNamed('test.zip');

Replies are listed 'Best First'.
Re^2: Problems with Archive::zip
by Martinw (Initiate) on May 18, 2010 at 15:50 UTC

    Thanks for explaining it is a simple way, I have it working

    sub compress { #subroutine to compress the directory tree in to backup.zip in the bac +kup location print "Backing up ".$STARTLOCATION."\n"; my $zip = Archive::Zip->new(); opendir (DIR, $STARTLOCATION) or die $!; while (my $file = readdir(DIR)) { # Use -f to look for a file next unless (-f $STARTLOCATION."\\".$file); $zip->addFile($STARTLOCATION."\\".$file, $file); print "Added $file to zip\n"; } closedir(DIR); unless ( $zip->writeToFileNamed($BACKUPNAME) == AZ_OK ) { die 'write error'; } print "Successfully backed up to ". $BACKUPNAME; }