What OS are you using?

My guess is that you could be on Windows. Although the NTFS filesystem does support longer path lengths, the predominate API that most Windows programs use has a max path length of ~250-260 characters for backwards compatibility. (I've seen different documentation referencing different values on what that max value is.) And most of the Perl modules (including File::Find) uses the API with the ~250-260 character limit on paths.

On Windows, I have encountered the issue described in File::Find's bug report #44819 about getting a "Can't cd" error message that has a lot of "/../" directories in the path. It's been a while since I hit that issue and if I remember correctly, using the no_chdir option of File::Find did not fix the issue. After modifying the source of File::Find as described in that bug report, I was able to get around the issue.

If you do decide to try using that, just keep in mind that the source code of the newer versions of File::Find is different and the portion that would need to be modified is not going to look exactly like what is described in the bug report. It's been a while since I tried using that, so I can't give you more details on what to look for. I should also point out that I don't know what the full effect of modifying File::Find's source as described in the bug report, which means that doing so may create problems. So proceed with caution if you want to try that work around.

Even if you're willing to try to modify your copy of File::Find as described above, you will still have issues if your path length exceeds the max path length of that Windows file API. I've recently been trying to figure out how to traverse a directory structure in Windows for directory structures that I know exceed the ~250-260 character limit. If I remember correctly, Path::Tiny (as suggested by GotToBTru) still had the same path length issue. Just wanted to point that out in case you really do have a genuine long path (> ~250-260).

If you do have long paths that you are working with, you might find Win32::LongPath to be useful - and it does provide a statL function that can provide mtime information that you are looking for. I have not tried looking into getting other modules (File::Find, Path::Tiny, etc.) to leverage Win32::LongPath, so I can't provide any guidance with that. I was able to use the logic from Re: Win32 Recursive Directory Listing and Win32::LongPath to successfully traverse a directory structure that had paths with more than 300 characters. In that code, I did leverage Path::Tiny to manipulate paths (basename, cannonpath, etc.) as long as I avoided using Path::Tiny to access the long paths (opening/reading files and directories, file copying, etc.).


In reply to Re: File and Folder length problems by dasgar
in thread File and Folder length problems by merrymonk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.