Reputation: 40748
I am trying to search for Perl files in directory tree. I want to exclude some directories from the result. Is this possible with Find::File::Rule
? I tried:
use warnings;
use strict;
use feature qw(say);
use File::Find::Rule::Perl;
my $dir='test';
my @files=File::Find::Rule->perl_file->name(qr/^.*debug.*\.(pm|pl)$/)->in($dir);
say join ("\n",@files);
To exclude the debug
sub folder from the result, but it does not work. It only checks the name of the file, not the path name.
Upvotes: 1
Views: 674
Reputation: 35198
There is an example of how to do this in the module documentation: Further Examples
ignore CVS directories
my $rule = File::Find::Rule->new; $rule->or($rule->new ->directory ->name('CVS') ->prune ->discard, $rule->new);
Note here the use of a null rule. Null rules match anything they see, so the effect is to match (and discard) directories called 'CVS' or to match anything.
This method often comes in handy for ignoring these like .git
directories as well.
Upvotes: 3