in reply to Re: Re: Need help with File::Find
in thread Need help with File::Find

Instead of changing the code, allow the user to pass some options in. If tachyon would be so kind as to allow me to lift his code:
use strict; use warnings; use File::Find; use Getopt::Long; use vars qw($all @datein @exts @excl $base); GetOptions( 'exts|t=s' => \@exts, 'excl|c=s' => \@excl, 'base|b=s' => \$base, 'all|a' => \$all, ); if (not $all) { @exts = qw( jpg gif tar gz bat txt ) unless @exts; @excl = qw( winnt cygwin ) unless @excl; } $base ||= '/cygwin'; my $exts = join '|', map{quotemeta} @exts; my $excl = join '|', map{quotemeta} @excl; find( sub { push @datein, $File::Find::name if !$exts or m/\.(?:$exts)$/oi and $File::Find::name !~ m!/(?:$excl)!oi ; }, $base, ); print "$_\n" for @datein;
Now you can call the script like so:
./find.pl -exts=txt -exts=gif -excl=nodes -base=.
or this if you want everything:
./find.pl -base=/ -all
If specifying the extensions one at a time becomes too tedious for you, you can rewrite the code to allow the user to pass a delimited string instead. Read up on the Getopt::Long docs for more info. Additionally, check out the Unix command find.

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

Replies are listed 'Best First'.
Re: (jeffa) 3Re: Need help with File::Find
by ppm (Novice) on Feb 26, 2003 at 17:14 UTC
    Hey,

    this snippet is very usefull for me .. thx a lot to you and all the people of perlmonks!

    ppm

Re: (jeffa) 3Re: Need help with File::Find
by ppm (Novice) on Feb 26, 2003 at 17:22 UTC
    Hm ... sorry for new question.

    i've i want use the script by shell (getopt) or over http .. how to write this down?

    this was my last question for that ;o)

    ppm