bydepth just means to process the contents of a directory before processing the directory itself. So for your example find . -depth -print (equivalent to setting bydepth) would print the following:
/user/user1/foo.bar
/user/user1
/user/user2
/user/user4
/user/user500/foo.bar
/user/user500
/user
Rather then the results from find . -print:
/user
/user/user1
/user/user1/foo.bar
/user/user2
/user/user4
/user/user500
/user/user500/foo.bar
What you might be thinking of is a breadth-first search that looks at all nodes the same depth down before moving on. You can't do this with File::Find or find since it would need to keep a lot of state kicking around to remember where to go next. It also would not do what you need since it would still traverse all files.
What (I think) you want to tell it is to stop looking if it is more than 2 directories in. The following wanted function looks at the current directory name and tells the find to stop looking deeper if there is a / in it.
sub wanted {
my $depth = $File::Find::dir =~ tr{/}{/};
$File::Find::prune = 1
if $depth == 1;
print("$depth $File::Find::name\n");
}
BTW you said that it would check up to 2 gig of files, remember that it does not actually need to look at the contents of the files, just their directory information. So it is still expensive, but unless you have lots of small files, it should be much smaller than 2 gig.
-ben |