One of our customers habitually use very long path names (several nested folders, with long names) and we routinely encounter "user education issues" in order to shorten the path to less than 260 characters.
Is there a technical solution available, can we flick some sort of switch in Windows 7 and Windows 2008 R2 to say "yeah just ignore these historical problems, and make +260 character path name work".
P.S. I have read and been totally unedified by Naming Files, Paths, and Namespaces
Just mentioning a trick I do not see mentioned here yet.
Take this file for example:
C:\Folder1\Really Long Path\Such Recursion\So Deep\Wow\Still Going\I will run out of ideas soon\I have organizational problems\Obsessive compulsive subdirectory disorder\Here is a guid for no good reason\936DA01F-9ABD-4d9d-80C7-02AF85C822A8\Almost there\Tax Returns\2013\2013_tax_return.pdf
This full file path is 290 characters long. The shell (Windows Explorer) and most command line utilities probably won't let you touch it.
Use the
subst
command like so:Now you can access (and delete, move, etc.) the file thusly:
X:\Still Going\I will run out of ideas soon\I have organizational problems\Obsessive compulsive subdirectory disorder\Here is a guid for no good reason\936DA01F-9ABD-4d9d-80C7-02AF85C822A8\Almost there\Tax Returns\2013\2013_tax_return.pdf
And now that file name is only ~235 characters or so, so you will not encounter the "Filename is too long" problems any more.
In the Windows API, there is an infamous constant known as
MAX_PATH
. MAX_PATH is 260 characters. The NTFS file system actually supports file paths of up to 32,767 characters. And you can still use 32,767 character long path names by accessing the Unicode (or "wide") versions of the Windows API functions, and also by prefixing the path with\\?\
.MAX_PATH
was set in stone a very long time ago in the Windows world. I think it has something to do with ANSI standards at the time... but it's one of those things that's very difficult for Microsoft to change now, as now we have thousands of programs and applications, including some written by Microsoft themselves, that useMAX_PATH
and would fail in strange new ways if the constant were suddenly changed. (Buffer overflows, heap corruption, etc.)The methods are there, but until Microsoft re-codes the file-browser widget we're pretty much stuck with that old problem. It's sub-optimal, but that's just how it works.
You can get around this limitation by using the \\?\C: notation. It's ugly, but it supports file lengths up to 2^15.
http://msdn.microsoft.com/en-us/library/aa365247(v=vs.85).aspx#maxpath
Microsoft now has an available fix for this beginning with Windows 10, which is explained in the Naming Files, Paths, and Namespaces MSDN article.
darthcoder already answered with details on the
\\?\C:
notation work-around, but there is now a registry key atHKLM\SYSTEM\CurrentControlSet\Control\FileSystem LongPathsEnabled (Type: REG_DWORD)
which can be used to remove MAX_PATH limitations for a single system. The article also mentions support for Group Policy control atComputer Configuration > Administrative Templates > System > Filesystem > Enable NTFS long paths
for organization or group-wide implementation if needed.