I don't think that File::Find is going to let you throw away directory subtrees that you don't like. You could put code into your wanted() method that will ignore files with a path of the form that you describe, but you're going (to the best of my understanding) end up having File::Find waste time by walking through whole subtrees that you'd rather ignore. You might try using the following idiom in the place of File::Find to accomplish what you want...

use strict; use Cwd; my $cwd = Cwd::getcwd(); my $directory = shift(@ARGV) || $cwd; $directory = $cwd . '/' . $directory unless $directory =~ /^\//; my @queue = ($directory); while (@queue) { my $node = shift(@queue); if (-d $node) { opendir(DIR, $node); push(@queue, map { $node . '/' . $_ } grep { $_ ne '.' and $_ ne '..' and $_ !~ /^_/ } readdir(DIR)); closedir(DIR); } else { do_your_stuff($node); } }

This will do a depth first search on either the current working directory, or the directory that you specify on the command line, and it will ignore all subtrees of directories beginning with _. I hope this helps, and I hope it doesn't turn out to be a horribly convoluted way of doing it if there is an easier way with File::Find.

Update: It was come to my attention that exploitation of the $File::Find::prune variable is a much more expeditious way of accomplishing a pruning. I confess! I confess! Now stop minus one-ing me, I admit the error of my ways.


In reply to Re: Pruning directory searches with File::Find by skyknight
in thread Pruning directory searches with File::Find by annie

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.