in reply to Checking subdirectories in a given path
use File::Find; $source = '/somedir'; $somefile = 'somefile.txt'; traverse(); sub traverse { my %opts = ( wanted => \&eval_files, ); finddepth(\%opts, $source); } sub eval_files { if (-f && $_ eq $somefile) { print 'Got ', $_,"\n"; } }
For each item within a directory, File::Find will invoke the sub &eval_files. eval_files() does blissfully throw away items that aren't files and will shriek if the the file matches the given filename. $_ contains magically the name of the current item (dir / file).
|
|---|