Hi all!
I came on the forum hoping to get some answers or at least some ideas.
I need to recurse on windows in a very deep directory structure some paths being even 500-600 chars long.
The recursive function works very well on linux but on windows just can't go over 260 chars path.
Thank you very much for any suggestion!

    You're going to have to give us a little more information than that... such as:

    1. The code you're using now that works on Linux but not on Windows

    2. The error message you're getting when you run that code on Windows

      Thank you for your quick reply!
      Exactly. On linux the script is working while on windows simply does not go deeper than 260 chars path. I simulated the situation on linux and works very well.
      By the way windows explorer can't read such files they use Total commander. I believe that the libraries for filesystem operations have this limitations. My only hope is that php has some proprietary library to read NTFS filesystems but I wasn't able to find anything.
      I don't know if I could use some relative pathnames just to cat on path length. But there are many dirs several levels deep and more than that the dir structure changes. And it is impossible to make some sort of mapping.
      It is a document archive... under construction...
      Please help me to find a solution to index all the files. At list some ideas... the thing that bothers me is that specific software like Tc can manage such long paths but windows itself not and now I discovered that on windows php too has this problem...

        You're right about it being a Windows limitation (versus an NTFS file system limitation):

        MSDN Library wrote:

        In the Windows API, the maximum length for a path is MAX_PATH, which is defined as 260 characters. A path is structured in the following order: drive letter, colon, backslash, components separated by backslashes, and a null-terminating character, for example, the maximum path on the D drive is D:<256 chars>NUL.

        Thanks, Micro$oft. 😉

        You could try this workaround:

        MSDN Library wrote:

        The Unicode versions of several functions permit a maximum path length of approximately 32,000 characters composed of components up to 255 characters in length. To specify that kind of path, use the "\?\" prefix. The maximum path of 32,000 characters is approximate, because the "\?\" prefix can be expanded to a longer string, and the expansion applies to the total length.

        (Both quotes taken from this MSDN Library page.)

        EDIT: A quick stab at using [man]file_get_contents/man with the Unicode version didn't turn out too well:

        Warning: file_get_contents(\?\C:\php\test.php): failed to open stream: Bad file descriptor in C:\php\test.php on line 2

        Since PHP 6 is supposed to be more Unicode-friendly (or so I thought?), however, perhaps it will make use of these Unicode API functions that the MSDN article above was talking about? I might play around with that later tonight and post back with my results...

        EDIT2: Forgot to come back and comment... PHP 6 is old news, I simply meant the "trunK" version, which is something like 5.3.99.

          Thank you!
          Tomorrow morning I will try it also and will see. the system is win 2008 server. I'm trying to help a friend that works mostly on asp. Ans ASP crashes, too... so i hoped that maybe php could help to index that..

            Write a Reply...