就像find
命令行工具,maxdepth
不限制匹配发生的地点;它限制了实际的遍历。
maxdepth( $level )
最多下降$level
(非负整数)起始点以下的目录级别。
就像find
命令行工具,mindepth
防止在特定深度之前执行所有测试。
mindepth( $level )
不要在低于以下的级别进行任何测试$level
(非负整数)。
Given what they do, they affect the entire search. As such, it's no surprise the mindepth
and maxdepth
from the outer rule object is the one used and the others are ignored.[1]
相同的解决方案适用于find
这里可以使用命令行工具。
find
:
$ find dir -wholename dir/b -prune -o -name '*.txt' -print
dir/a/b/c.txt
dir/a/b/d.txt
dir/a/c/q.txt
dir/q.txt
文件::查找::规则:
$ perl -MFile::Find::Rule -e'
my ($dir) = @ARGV;
CORE::say for
File::Find::Rule
->or(
File::Find::Rule->exec(sub { $_[2] eq "$dir/b" })->prune->discard,
File::Find::Rule->name("*.txt"),
)
->in($dir);
' dir
dir/q.txt
dir/a/b/c.txt
dir/a/b/d.txt
dir/a/c/q.txt
另一种方法是使用 File::Find::Rule 构建要搜索的目录列表,然后使用 File::Find::Rule 的其他用途搜索这些目录。 (Perl 相当于find ... -print0 | xargs -0 -I{} find {} ...
.)
-
The find
命令行实用程序以不同的方式处理错误的输入。
$ find dir -type d -mindepth 1 -maxdepth 1 -name b -prune -o -name '*.txt' -print
find: warning: you have specified the -mindepth option after a non-option argument (, but options are not positional (-mindepth affects tests specified before it as well as those specified after it). Please specify options before other arguments.
find: warning: you have specified the -maxdepth option after a non-option argument (, but options are not positional (-maxdepth affects tests specified before it as well as those specified after it). Please specify options before other arguments.
dir/q.txt