Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Zip only files, not directory hierarchy.

by linuxer (Curate)
on May 14, 2014 at 18:39 UTC ( [id://1086070]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1086070]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2024-04-19 13:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found