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

Wondering if File::Find is the right technique.. Warning---- I'm a seasoned beginner to perl!!! I'd like to start in a directory and get all the filenames that end in ".zip" that are found in all the subdirectories. Eventually I'd like to extract a file from each of these zip archives. I think that File::Find is the right way to get at all the zip files, but I can't find a useful example to follow. The ones I've found are either an inch long, or a mile long. Any suggestions? --Mark

Replies are listed 'Best First'.
Re: File::Find question
by tachyon (Chancellor) on Apr 17, 2002 at 20:02 UTC
    use File::Find; my $root_dir = '/files/misc/; sub find_zip { print "Found zip file $_\n" if /\.zip\z/; } find ( \&find_zip, $root_dir );

    find() traverses the directory tree under $root_dir and passes the name of every file in $_ to the find_zip() 'call back' sub. Note we use a sub reference as shown in find. The reference is indicated by the \ before the &

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Re: File::Find question
by data64 (Chaplain) on Apr 17, 2002 at 20:11 UTC

    Go with the inch long examples.

    Below is some sample code I threw together.

    #!perl use strict; use warnings; use File::Find; my @sourcedirs = ("." ); sub wanted { my $filename = $File::Find::name; if ( $filename =~ m/\.zip$/i ) { #is a zip file #do something print( "$filename\n" ); } } print( "Looking for zip files in @sourcedirs\n" ); find( \&wanted, @sourcedirs ); print( "---------Done-----------\n");

    <cite>Just a tongue-tied, twisted, earth-bound misfit. -- Pink Floyd</cite>