heigold1 has asked for the wisdom of the Perl Monks concerning the following question:

I don't know why this doesn't work, but the addDirectory method of Archive::Zip just doesn't add anything.

It doesn't crash the script, it doesn't produce any errors or warnings.

The directory is in the same folder as the script, and all the other files add perfectly fine, and a perfect zip file is produced.

Its just that the zip is produced without the directory in it

Here is the script:

--------------------------------------------------

#!/opt/ActivePerl-5.6/bin/perl # Archive::Zip is available for ActiveState perl use strict; use warnings; use Archive::Zip qw ( :ERROR_CODES :CONSTANTS ); my $zip = Archive::Zip->new(); my @files = glob("*.txt"); foreach (@files) { my $member = $zip->addFile($_); die "Cannot add $_ to zip!" unless $member; } ############################## ### Right here is the addDirectory ### ############################## $zip->addDirectory("dir1"); $zip->writeToFileNamed( "zipfile.zip" );

Edit: g0n - code tags

Replies are listed 'Best First'.
Re: $zip->addDirectory isn't doing anything.
by starX (Chaplain) on Jun 21, 2007 at 21:04 UTC
    First, you're really going to want to put that code between code tags, it makes it easier to read and is good practice, etc.

    Second, Have you tried checking the return value of addDirectory()? According to what I understand from the description, it should be returning the new member directory. Also, have you tried putting that part of your operation in an eval block? If so, what kind of error do you get back? maybe something as simple as modifying your error handling above (die "Cannot addDirectory to zip $!" unless $zip->addDirectory("dir1");) might give you some clues.

Re: $zip->addDirectory isn't doing anything.
by FunkyMonk (Bishop) on Jun 21, 2007 at 20:31 UTC
      Hi FunkyMonk. addTree just crashes the script. I'm really stuck here.
        What does "crashes the script" look like?
Re: $zip->addDirectory isn't doing anything.
by Anonymous Monk on Jun 22, 2007 at 05:22 UTC