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!

Replies are listed 'Best First'.
Re: File::Find how to prevent processing the subdirectory
by kennethk (Abbot) 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!