in reply to using file::find::name and file tests
A simple test shows what is going on:
use strict; use warnings; use File::Find; find (\&wanted, '..'); sub wanted { if (-e $File::Find::name) { print "Found $File::Find::name\n"; } else { print "Didn't find $File::Find::name\n"; } }
Prints in part (Windows XP):
Found .. Didn't find ../Ook.pl Didn't find ../test2.out.txt Didn't find ../test2.pl Didn't find ../test2.txt Didn't find ../test3.txt Didn't find ../test4.txt Didn't find ../Job Found ../Job/Func.pm Found ../Job/Game.pl Found ../Job/Game.pm Found ../Job/1st Didn't find ../Job/1st/Func.pm Didn't find ../Job/1st/Game.pl Didn't find ../Job/1st/Game.pm Didn't find ../tk Found ../tk/tkTest.pl Found ../tk/tkTest.vpd
From which you can see that the directory passed into find is concatenated onto the front of the relative path. That is just fine if the path passed in is absolute, but can be a real pain if it it is relative because (from the find docs):
Additionally, for each directory found, it will chdir() into that directory
means that the path is broken when the directory is changed away from the current directory when the find was called.
You can fix the problem by specifying no_chdir thus:
find ({wanted => \&wanted, no_chdir => 1}, '..');
|
|---|