Jump to content
Bill Meyer

Windows PATH length limit?

Recommended Posts

I would have thought that it should be easy to find documentation on the maximum Windows PATH length. I have found many articles, none of them comprehensive. The only specification which seems to be straightforward is the MAX_PATH = 260 limit on the file path.

What I am looking for, however, is whether the full PATH variable has a specified limit.

Share this post


Link to post
Posted (edited)

2048

 

 

Just for the record. Nothing to do with your question.

1 hour ago, Bill Meyer said:

The only specification which seems to be straightforward is the MAX_PATH = 260 limit on the file path.

 

For file I/O, the "\\?\" prefix to a path string tells the Windows APIs to disable all string parsing and to send the string that follows it straight to the file system. For example, if the file system supports large paths and file names, you can exceed the MAX_PATH limits that are otherwise enforced by the Windows APIs. For more information about the normal maximum path limitation, see the previous section Maximum Path Length Limitation.

Because it turns off automatic expansion of the path string, the "\\?\" prefix also allows the use of ".." and "." in the path names, which can be useful if you are attempting to perform operations on a file with these otherwise reserved relative path specifiers as part of the fully qualified path.

Many but not all file I/O APIs support "\\?\"; you should look at the reference topic for each API to be sure.

Note that Unicode APIs should be used to make sure the "\\?\" prefix allows you to exceed the MAX_PATH.

 

Edited by Attila Kovacs

Share this post


Link to post

That works only if 

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem] "LongPathsEnabled"=dword:00000001

is set

 

  • Like 1

Share this post


Link to post

This morning, a colleague offered this:
https://devblogs.microsoft.com/oldnewthing/20100203-00/?p=15083
It is likely to be the best explanation to be found. 

Share this post


Link to post

In theory, up to 32K:

 

What is the maximum length of an environment variable?

20 hours ago, Attila Kovacs said:

2048

The actual PATH environment variable itself is not limited to that length, but in practice, various tools that set the path, and various APIs that use the path, are limited.

 

https://superuser.com/questions/1385854/how-do-i-bypass-restrictions-on-the-length-of-the-path-variable

 

https://www.askwoody.com/forums/topic/what-is-the-real-path-length-limit-in-windows-10/

 

https://learn.microsoft.com/en-US/troubleshoot/windows-client/shell-experience/command-line-string-limitation

 

That last one theorizes that the PATH could be as much as 8K, not 2K.

 

So, the limitation is not so much on the variable itself, but on how it's used. 

 

Share this post


Link to post

 

On 5/28/2024 at 8:00 AM, Remy Lebeau said:

Using tricks like this to is how I've gotten several versions of Delphi installed on one box (along with everything else I use regularly). The PATH setting on my machine only takes 1,876 characters but when fully expanded, it's 6,327 characters long! Every time I install another version of Delphi, I ignore the "PATH is close to the limit" warning, then go edit it later, creating, for example, D23 to replace "C:\Program Files (x86)\Embarcadero\Studio\23.0".

image.thumb.png.8eed4f4626a0d20a5e1137cb6f079123.png

Share this post


Link to post
1 hour ago, Sherlock said:

Uwe Raabe Has written a nifty tool to circumvent this

That looks pretty cool. I'm a little nervous about running a program that messes with such an important part of Windows operations but it looks like it would work well.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×