http://www.perlmonks.org?node_id=1086070


in reply to Zip only files, not directory hierarchy.

Have a look at the perldoc of IO::Compress::Zip. It mentions an option FilterName, which could be used.

Quoting:

...

Filtername => sub { ... }

... For example, the code below shows how FilterName can be used to remove the path component from a series of filenames before they are stored in $zipfile.

sub compressTxtFiles { my $zipfile = shift ; my $dir = shift ; zip [ <$dir/*.txt> ] => $zipfile, FilterName => sub { s[^$dir/][] } ; }
Update

Did a test; it works ;-)

#! /usr/bin/env perl use strict; use warnings; use File::Basename qw( basename ); use IO::Compress::Zip qw( zip $ZipError ); my @files = glob( 'data/*/*.dat' ); my $zipfile = './zipped.zip'; print "zipping $_\n" for @files; zip [ @files ] => $zipfile, FilterName => sub { $_ = basename($_); }; __END__ # source files data/foo/FOO.dat data/bar/BAR.dat # files in zip (according to 'unzip -l') FOO.dat BAR.dat