in reply to File::Find giving unexpected results under windows

Sounds like a bug in its handling of drive-prefixed relative paths. Keep in mind that "«F:Users/Joel/Documents/My Music»" means "«Users/Joel/Documents/My Music» relative to the F:'s current directory".

Telling File::Find not to chdir (which is not a bad idea anyway) and/or switching to find(\&process, 'F:\\'); (which is probably what you meant anyway) should fix it.

Replies are listed 'Best First'.
Re^2: File::Find giving unexpected results under windows
by Anonymous Monk on Oct 26, 2011 at 10:00 UTC

    hi,

    when i used File::Find to search a whole drive under windows sometimes my script died with e.g.

    Can't cd to ../../../../../../../../../../../../.. from C:/Dokumente und Einstellungen/User/Anwendungsdaten/Macromedia/Flash Player/#SharedObjects/3V6TWZWS/static.sf-cdn.com/MD5=02b6557eb0995f2859ece9db3a0ce8fb/default/swf/v4_0/platform/bin/com/snapfish/modules/controllers/upload/UploadController.swf at D:/usr/lib/File/Find.pm line 983, <STDIN> line 1.

    i've learned that this is due to the Windows MAX_PATH length of 260 chars and the chdir() implementation (which seems to append all the ../../../../../.... to the actual path).

    a simple solution shifts that problem almost out of the way (up to a max. pathlength of 258 chars in windows, does not interfere with other os)

    insert in Find.pm at line 983:

    chdir ('..') or die "Can't cd to .. from $dir_name" while $tmp =~ s/^\.\.\///o;

    then that code should (nice) look like

    $tmp = join('/',('..') x ($CdLvl-$Level)); } chdir ('..') or die "Can't cd to .. from $dir_name" while $tmp =~ s/^\.\.\///o; die "Can't cd to $tmp from $dir_name" unless chdir ($tmp);