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

Hello,

What is the best way to zip all the files in a directory ending with *.log?

I am using Archive::Zip module. But, I am only able to add files one-by-one by the addFile command. The addDirectory command does not seem to work.

Thanks

Replies are listed 'Best First'.
Not true...
by Luca Benini (Scribe) on Nov 23, 2004 at 19:20 UTC
    from perldoc Archive::Zip
    my $zip = Archive::Zip->new(); # add all readable files and directories below . as xyz/* $zip->addTree( '.', 'xyz' ); # add all readable plain files below /abc as def/* $zip->addTree( '/abc', 'def', sub { -f && -r } ); # add all .c files below /tmp as stuff/* $zip->addTreeMatching( '/tmp', 'stuff', '\.c$' ); # add all .o files below /tmp as stuff/* if they aren't writable $zip->addTreeMatching( '/tmp', 'stuff', '\.o$', sub { ! -w } ); # add all .so files below /tmp that are smaller than 200 bytes as stuf +f/* $zip->addTreeMatching( '/tmp', 'stuff', '\.o$', sub { -s < 200 } ); # and write them into a file $zip->writeToFileNamed('xxx.zip'); # now extract the same files into /tmpx $zip->extractTree( 'stuff', '/tmpx' );
Re: Zip Files in a Directory
by kappa (Chaplain) on Nov 23, 2004 at 17:48 UTC
    With addDirectory you won't be able to filter files by wildcard, anyway. So, addFile is the way and not a bad one because Archive::Zip will write the result in one operation in the end.
    --kap