I'm trying to do what I thought would be a very simple task: Create a zipfile with the contents of an entire directory, passed in to a function. I wrote (with very minor changes from the real code):

sub create_zipfile { my ($path) = @_; my $UUID = Data::GUID->new->as_string(); my $zipfile_name = $UUID . ".zip"; my $full_path = $path . "/" . $zipfile_name; my $zip = Archive::Zip->new(); $zip->addTree($path, undef); if ( ! $zip->writeToFileNamed($full_path) == AZ_OK ) { print "Error writing zipfile: $!\n"; } return $full_path; }
I tried to run this as "my $filename = create_zipfile("/path/to/directory");", and it fails with IO error: Can't open /path/to/directory/0BE30138-93B4-81EE-93CD-DC592DB8B6F0.zip for write : No such file or directory. Which--I know there's no such file or directory, I'm asking it to be created.

In a previous version of this--and I don't remember what's different, and can't replicate it--it did create a zipfile, but it was empty.

I'd be grateful for a pointer; this would seem to be the main way one would use this module, but I can't find discussion of how to do this! Thanks.

In reply to Archive::Zip: save entire directory? 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.