Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

File::Find how to prevent processing the subdirectory

by Anonymous Monk
on Feb 27, 2012 at 16:36 UTC ( #956477=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,
how could I prevent File::Find from processing the files in the subdirectory (i.e. it should process the files in the directory but not in the subdirectory of this directory)? The option no_chdir=>1 seems not to be helpful here.
Thank you!

Comment on File::Find how to prevent processing the subdirectory
Download Code
Re: File::Find how to prevent processing the subdirectory
by kennethk (Monsignor) on Feb 27, 2012 at 16:44 UTC

    If you do not need to traverse a directory tree, why do you want to use File::Find? Combining standard directory operations (e.g. readdir) and file operations (-X) should suffice. This sounds a lot like an XY Problem.

    #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

Re: File::Find how to prevent processing the subdirectory
by moritz (Cardinal) on Feb 27, 2012 at 17:44 UTC
Re: File::Find how to prevent processing the subdirectory
by nemesdani (Friar) on Feb 27, 2012 at 20:18 UTC
    Use the preprocess option in find.
    my $dir = "wherever"; my %options = ( preprocess => \&filterOutSubdir, wanted => \&wanted, ); finddepth(\%options, $dir);
    I just learned this yesterday from the monks :). It is a really powerful tool. More here: Beginners guide to File::Find
Re: File::Find how to prevent processing the subdirectory
by Anonymous Monk on Feb 28, 2012 at 07:49 UTC
    Thank you all very much!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://956477]
Approved by kennethk
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2014-10-21 04:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (95 votes), past polls