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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.