June 11th, 2025
heartlike3 reactions

Removing the MAX_PATH restriction on paths applies only to paths

A customer was playing around with Windows long paths and found that even though they used the \\?\ long path prefix, they still couldn’t use a long path.

The documentation on the maximum path limitations say that the \\?\ prefix is always available. Just to make sure, they set the registry key and created the corresponding manifest entry to enable long paths without the \\?\ prefix, but that didn’t help.

They wanted to know what they were doing wrong and included a short program to demonstrate.

The path in their sample program was C:\looooooooo⟦ 1000 more o's ⟧ooong.txt. This is well under the 32,767 limit,¹ so why doesn’t it work?

Although the \\?\ prefix and the long path setting raise the path limit to 32,767 characters, the length of each individual component of the path is also subject to a length limit. You can query this limit by calling Get­Volume­Information and checking the maximum component length. Values you might see include 255 (exFAT, NTFS), 110 (Joliet CD-RW in Unicode mode), and for network volumes, it’s determined by the network protocol.

In the customer’s case, they were passing a file name that was over 1000 characters long, which probably exceeded the maximum component length.

They can try again by using a path with longer individual components, where each one is only 100 (say) characters long, but which collectively add up in length to something greater than MAX_PATH (260).

¹ Note that the 32,767 limit includes any expansion that occurs during internal processing, so the practical limit for applications is a bit less than that.

Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

6 comments

Discussion is closed. Login to edit/delete existing comments.

Sort by :
  • Adam Jensen

    Why do I need to set some registry value to enable long path support?

    • Danielix Klimax

      You’re on Old New Things, I’d think it is obvious…

      Hint: What happens to old program getting long path…

      • Michael Taylor

        >> Old applications do not have a longPathAware manifest so nothing happens.

        That's funny. Clearly you weren't writing code back in the days when this was first introduced. The 2 most common results of enabling LFN support on an app that didn't support them was: buffer overflow and inaccessible files, in my experience.

        Buffer overflow was the worse and a security risk. This was back before security was really at the top of everyone's list. The most common code used to get a filename allocated a character array of MAXPATH size. This was more efficient and easier to write then dynamically allocating...

        Read more
      • ‪ ‪

        Old applications do not have a longPathAware manifest so nothing happens.

    • Georg Rottensteiner

      Only if you want to use long paths without the \\?\ prefix. With the prefix you don’t need to do that.
      In my code base I modify all file/path accesses to use the \\?\ prefix internally.

      • Vladimir Vissoultchev

        Extremely dangerous as users might then produce with your program some “undeletable” files on their Desktop.