in reply to Formatting Regex for File::Find::Rule

$rule->new->directory->name( @dirExclusionsQR )->prune->discard

->prune means not to descend into that directory. Your fist match is ., so File::Find::Rule isn't even descending past the base directory. Second, note that ->name matches on the basename only, so the extra slashes you've got in there won't match. This works for me, hopefully it's what you're looking for:

use warnings; use strict; use File::Find::Rule; my $tagLocation = '...'; my @dirExclusions = qw/ LOG cache AVCHD /; my $rule = File::Find::Rule->new; $rule->or( $rule->new->directory->name( @dirExclusions )->prune->discard, $rule->new->directory ); my @fileList = $rule->in($tagLocation);

Replies are listed 'Best First'.
Re^2: Formatting Regex for File::Find::Rule
by springgem (Novice) on Apr 09, 2021 at 15:20 UTC

    Thanks for the quick reply. Makes sense, though '*.*' does continue and returns files as expected. I'll be careful about '.' going forward. That's a wise point.

    Do you have any ideas as to why I can't get qr// to work inside name()?

      '*.*' does continue and returns files as expected

      '*.*' is being expanded to a regular expression by File::Find::Rule (more specifically, by glob_to_regex from Text::Glob): m{(?^:^(?=[^\.])(?:(?!\/).)*\.(?:(?!\/).)*$)}

      Do you have any ideas as to why I can't get qr// to work inside name()?

      ->name( qr/LOG|cache|AVCHD/ ) works for me the same as my array suggestion above - like I said it won't work if you keep the slashes in.

        Perfect! Got it to work. The issue was indeed the period in the qr, as you said. Changed it to '\..+' in the pattern, to bypass the current directory, and all is good. Thanks for putting up with me. I knew it was something stupid on my part.