43

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

3
  • 3
    Here we are in 2018 and the problem still exists in ROBOCOPY. 255 limit. Those exceeding it simply beep but don't copy.
    – SDsolar
    May 23, 2018 at 23:36
  • @SDsolar: are you using an old version of robocopy?
    – Naikrovek
    Nov 5, 2018 at 8:36
  • Yes, was going to say the same - one has to use robocopy specifically because it can handle long paths... Apr 8, 2019 at 11:33

5 Answers 5

13

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.

2
  • 7
    Bug in MS software that has been unfixed for few OS releases, that's a new one... Nov 24, 2011 at 0:01
  • 3
    Windows 10 1607 finally fixed the file-browser problem and has some wizardry to fool Win32 applications in to working in this strange new world of huge paths: howtogeek.com/266621/…
    – HackSlash
    Jul 31, 2018 at 22:44
35

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:

subst X: "C:\Folder1\Really Long Path\Such Recursion\So Deep\Wow"

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 use MAX_PATH and would fail in strange new ways if the constant were suddenly changed. (Buffer overflows, heap corruption, etc.)

1
  • 11
    I've been taking an approach similar to subst by using directory junctions, which may be more convenient to cleanup if you're just looking to make a few quick changes. I use Link Shell Extension, but you can just use the mklink command like so: mklink /J C:\Wow "C:\Folder1\Really Long Path\Such Recursion\So Deep\Wow". Sep 27, 2015 at 3:10
14

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

7
  • 2
    Yeah I read that, as I said (see my link). But how do I benefit from it exactly? Can I map a drive to \\?\something for example. I don't understand. The article is intended for programmers using windows APIs. Whilst I do code in .NET as the need arises I don't use C++ etc. and can't see how this is relevant for my customers staff who are using windows explorer and the common file dialog etc. Feb 9, 2011 at 0:08
  • 1
    Ultimately, there is none. :-/ Sadly.
    – Chris K
    Feb 9, 2011 at 3:35
  • @ChristopherEdwards You can create junctions to points lower in folder hierarchy. Nov 23, 2011 at 23:59
  • 1
    @ChristopherEdwards you could do a link c:\usr-data to `c:\Users\VeryLongUserName\LongFolderName` and tell him to use the former, but if he regularly names folders in 40-something characters then this won't help... Nov 29, 2011 at 20:50
  • 2
    7-zip will happily browse and copy in \\?\C: notation, for what it's worth. Nov 24, 2015 at 6:17
10

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 at HKLM\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 at Computer Configuration > Administrative Templates > System > Filesystem > Enable NTFS long paths for organization or group-wide implementation if needed.

6
  • I've not had time for thorough testing, but I've seen mixed results with this solution so far, and can't confirm that this solves the problem for Windows [file] Explorer.
    – JimNim
    Apr 19, 2017 at 13:57
  • 2
    This doesn't work in File Explorer because although the system and NTFS can handle long paths, Explorer cannot until it is itself re-coded.
    – ingyhere
    Dec 25, 2017 at 18:50
  • PS, you will need to use one of the copy programs in this SO link on top of Explorer to actually make it work.
    – ingyhere
    Dec 25, 2017 at 18:51
  • 1
    Good info! I will probably just stick to Robocopy in that case.
    – JimNim
    Dec 26, 2017 at 5:59
  • where is darthcoder's posting? did he delete it?
    – barlop
    Apr 29, 2020 at 11:21
0
#If you are accessing files locally
get-childItem -LiteralPath \\?\e:\TopFolders\

#If you are accessing files through network Share
get-childItem -LiteralPath \\?\UNC\MyFileServerHostName\Share\

source link

Not the answer you're looking for? Browse other questions tagged or ask your own question.