No offense intended but it looks like a lot of rookie mistakes here. Maybe you copied and pasted some code from examples. But it is really tough to debug something like this without understanding each part.
For example you have a loop where for each file in @files you do another foreach loop on a glob of the individual file. This makes no sense because you already have the file name. How about making a test program that has a print statement inside the foreach loop that prints "addFile($filename)\n" so you know what the loop is doing.
For each file in @files you call addDirectory($file_path). Either add the directory or add individual files, not both.
For each file in @files you call writeToFileNamed(). This should be done once after you have added all the files to $zip.
To answer your question about adding the log file: have a look at this from http://search.cpan.org/~adamk/Archive-Zip-1.30/lib/Archive/Zip.pm
overwrite() Write back to the original zip file. See overwriteAs() above. If the zip was not ever read from a file, this generates an error.
You need to read a zipfile into $zip before you can call $zip->overwrite().
Try something like this:
if (-e $zip_path) { unless ( $zip->read( $zip_path ) == AZ_OK ) { die "$zip_path read error.\n"; } print "read $zip_path\n"; } else { die "Error: $zip_path should have just been created."; } # copy those from dir to zip. foreach (@files2copy) { die "File missing: $dir$_" unless -e "$dir$_"; unless ( $zip->addFile( "$dir$_" , $_ )){ die "couldn't add $dir$_ to $zip_path."; } } unless ( $zip->overwrite() == AZ_OK ) { die "$zip_path write error"; }
This also shows how to add files with a different name or path than the original full path. $zip->addFile( "$dir$_" , $_ ) Here I added only the relative path starting at the path to $dir. You could also just put the filename. But without paths don't repeat filenames unintentionaly. zip archives allow multiple copies of the same file and Archive::Zip complies.
In reply to Re: Zipping Files Help!
by Lotus1
in thread Zipping Files Help!
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |