简体   繁体   English

perl-File :: Find :: Rule仅在顶层排除单个目录

[英]perl - File::Find::Rule to exclude a single dir only for the top level

I tried the following to exclude the directory 'CVS' 我尝试了以下排除目录“ CVS”的方法

my $rule = File::Find::Rule->new;
$rule->or($rule->new->directory->name('CVS')->prune->discard, $rule->new);

But however this effectively excludes any CVS directories that live inside the directory tree. 但是,这实际上排除了目录树中的所有CVS目录。

Here is an example : 这是一个例子:

  • source/CVS (should be excluded) 来源/ CVS(应排除)
  • source/A/CVS (should not be excluded) 源/ A / CVS(不应排除)
  • source/B/ 源/ B /
  • source/C/dog/CVS (should not be excluded) 源/ C /狗/ CVS(不应排除)

You could use the Perl equivalent of find dir -wholename dir/CVS -prune -o -print . 您可以使用与find dir -wholename dir/CVS -prune -o -print等效的Perl。

say
   for
      File::Find::Rule
         ->or(
            File::Find::Rule->exec(sub { $_[2] eq "$dir/CVS" })->prune->discard,
            File::Find::Rule->new(),
         )
         ->in($dir);

Another approach would be to use File::Find::Rule to build a list of directories to search, then search those directories with another use of File::Find::Rule. 另一种方法是使用File :: Find :: Rule构建要搜索的目录列表,然后使用File :: Find :: Rule的另一种用法搜索这些目录。 (The Perl equivalent of find ... -print0 | xargs -0 -I{} find {} ... .) (Perl等价于find ... -print0 | xargs -0 -I{} find {} ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM