OzzyOsbourne has asked for the wisdom of the Perl Monks concerning the following question:

Is there a depth or character limitation within File::find? I couldn't find one in the documentation or on the site.

I am running a file::find against a server,

and the script will sometimes die with a message similar to:

Can't cd to //server1/e/users/user111/Recent/DADrawin.gSu/WINDOWS/Profiles/user1111/Recent/DADrawin.gSu/WINDOWS/Profiles/user1111/Recent/DADrawin.gSu/WINDOWS/Pro files/user111/Recent/DADrawin.gSu/WINDOWS/Profiles/user111/Recent/DADrawin.gSu/W INDOWS/Temporary Internet File.. at C:/Program files/PERL/lib/File/Find.pm line 1

The script runs fine most of the time.

  • Comment on Is there a depth limitation to File::find

Replies are listed 'Best First'.
RE: Is there a depth limitation to File::find
by tye (Sage) on Aug 23, 2000 at 22:46 UTC

    That smells like a DOS limit, not a Perl limit. Under WinNT and later, you can use paths like "//?/e:/..." or "//?/UNC/server1/e/users/..." to turn off path parsing to use paths larger than 260 characters. But I don't think there is a way to do that for chdir() -- just via CreateFile() (see Win32API::File).

            - tye (but my friends call me "Tye")
Re: Is there a depth limitation to File::find
by merlyn (Sage) on Aug 23, 2000 at 22:41 UTC
Re: Is there a depth limitation to File::find
by maverick (Curate) on Aug 23, 2000 at 22:42 UTC
    Some file systems have limits for how long a path or filename can be. You have a path that's about 260 characters long. If I'm not mistaken Linux has a 255 character limit. See if you can find the set of paths for which this fails. I bet they'll all be extremely long.

    /\/\averick

      According to my linux/limits.h, the maximum number of characters is 4095, not 255.
        You're right. It's 255 for the max filename and 4095 for the max pathname. I was thinking they were the same size for some reason...

        /\/\averick

Clarification on the problem
by OzzyOsbourne (Chaplain) on Aug 24, 2000 at 19:40 UTC

    Here is the way simplified code. File::Find won't open a directory over 260 characters (it looks like an O/S limitation - thanks, everyone). I've tried putting if length statements into Wanted, but by then it is too late. I've tried wrapping the find function in an eval, but then it's too early.

    What I want it to do is if it hits a directory over 255 characters, do a next or something. I want it to stick its head in the sand, and clap its hands over its little PERL ears and ignore the error.

    Any ideas?

    use File::Find; $dir1="//server01/x\$/users/userguy"; print "finding media files on $dir1\.\.\.\n"; find(\&wanted, $dir1); sub wanted { if (!("$File::Find::dir"=~/}/)&&(/mp3$|avi$|exe$|mpg$|wav$|zip$/i) +){ print "$File::Find::dir/$_\n"; } }

RE: Is there a depth limitation to File::find
by OzzyOsbourne (Chaplain) on Aug 24, 2000 at 18:31 UTC
    I should have mentioned that I am using WIN2K PROF. This may indeed be a limitation of the O/S. I've been trying to do manual dir's over 260, and it's failing the same as if I were using PERL.

    Thanks for the help.