in reply to Pruning directory searches with File::Find

In the File::Find wanted subroutine ...
if (-d _ and /^_/) { $File::Find::prune = 1; return; }
... untested of course. See "perldoc File::Find".

Update: Or you may want to use "-d $_" instead.

bluto

Replies are listed 'Best First'.
Re^2: Pruning directory searches with File::Find
by particle (Vicar) on Jul 25, 2003 at 20:57 UTC

    actually, you should use:

    use File::Spec 'catfile'; ## later, in sub wanted... if( -d catfile( $File::Find::dir, $_) && m/\A_/) { $File::Find::prune= 1; return; }

    you need to specify the absolute path to the file system object you're accessing. $_ stores the name relative to the current search directory within File::Find. also, File::Spec will give you the platform independence you secretly crave ;P

    but, overall, i'd still suggest broquaint's method. File::Find::Rule makes code like this easier to code, understand, and maintain.

    ~Particle *accelerates*

      I'm not sure why you'd want to do this unless you specified "no_chdir" (see the man page). You are already chdir'd there so $_ is fine. In anycase, you should be able to use $File::Find::name if you are paranoid and skip the catfile().

      bluto