Subject: | maxdepth/mindepth not what they seem (?) |
[Well, shoot, I looked at 20_02 and you already have a comment about this. Ah well, maybe the below will give you some ideas]
Started out wanting to compare files under a couple of directory
trees to find duplicates. (yet another one of those...)
During testing I figured the easiest way to limit runtime was
to just say "don't descend more than a couple levels". So I
used maxdepth(2). And it didn't return anything. >-O
Played with it some more and found out that maxdepth() cared
about all the directory component levels, including the levels
Show quoted text
>>in the original starting paths<<. Ugh!
If I use two starting directories, oh say, c:/perl/lib and
c:/perl/site/lib (smile if you will) then mindepth and
maxdepth lose some (a lot?) of their usefulness because the
starting paths have differing numbers of components.
I'd kinda read the docs as meaning that the starting paths would
be taken into account and it would be the _relative_ depths that
would be tested.
maxdepth( $level )
Descend at most $level (a non-negative integer) levels of
directories below the starting point.
Started wandering about and found $File::Find::topdir which the
docs say is present (must be present?) for compatibility reasons.
And without the follow options then this is the current starting
path value. Using this we can derive our current partial path.
After several iterations I've an example exec() routine. This
basically does what you are doing, except first stripping off
the starting path. I got rid of your special case lopping off
the leading './' by using another File::Find variable. There
is also the special case of examining the starting path itself.
my $maxdepth = undef; $maxdepth = 2;
my $mindepth = undef; # $mindepth = 3;
$ffr->exec( sub
{
my( $fullpath, $topdir ) = ($File::Find::name, $File::Find::topdir);
return 1 if length($topdir) >= length($fullpath);
# could use if $topdir eq $fullpath; instead
my $partpath = substr( $fullpath, length($topdir)+1);
my $partdepth = scalar File::Spec->splitdir($partpath);
$File::Find::prune = 1
if defined $maxdepth && $partdepth > $maxdepth;
return
if defined $mindepth && $partdepth <= $mindepth;
1;
}
);