in reply to Re: How do I search for a specific directory on a remote PC?
in thread How do I search for a specific directory on a remote PC?

File::Find works fine. I use it whenever I have a need to locate files. You just have to understand how to use the wanted function. It uses '/' instead of '\\' internally, but that's only an issue at display time. The following prints out directories it finds in a tree, starting in the current directory. You can easily modify it to act on files, store the names in a data structure, etc. Scoping issues are more quickly handled in the last example because you're not changing scope.
use File::Find; find ( ref to function, start path(s) ) e.g.: use File::Find; find (\&wanted, '.'); sub wanted { print($File::Find::dir, "/$_\n") if -d $_; } or, just as good: use File::Find; find ( sub {print($File::Find::dir, "/$_\n") if -d $_}, '.');
See perldoc File::Find for how to use $File::Find::dir and $_ in the wanted function.

Replies are listed 'Best First'.
Re: Re: Re: How do I search for a specific directory on a remote PC?
by Anonymous Monk on Jan 05, 2002 at 00:40 UTC
    I decided my reply was incomplete, given the exact question you had. Here's some code that does it.
    use File::Find; use strict; our $belowpath = "common files"; our %found_dirs; find( \&foobar, 'c:/program files'); sub foobar { if ( $File::Find::dir =~ /$belowpath$/i && -d $_ ) { my $found = "$File::Find::dir/$_"; $found =~ tr/\//\\/; print "$found\n"; } }
    This prints:
    c:\program files\Common Files\Network Associates c:\program files\Common Files\Adobe c:\program files\Common Files\InstallShield c:\program files\Common Files\Symantec Shared c:\program files\Common Files\Services c:\program files\Common Files\System c:\program files\Common Files\ODBC c:\program files\Common Files\Microsoft Shared