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


In reply to Re: The situational efficiency of File::Find by knobunc
in thread The situational efficiency of File::Find by OzzyOsbourne

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.