21

after a long research, I finally found out that pathnames cannot be longer than 256 characters even in the latest Microsoft Windows 7. I really don't get it why there is such a stupid limitation, since NTFS can handle up to ~32,000 characters path length without any problem since more than a dozen years! Isn't there any possibility to change that? Or are there any practical solutions to avoid that?

260 characters are just very few for even simple use cases like some nested photo directories with long file names.

HopelessN00b
  • 53,385
  • 32
  • 133
  • 208
  • 2
    I think the worry is that there are older programs that have a hardcoded idea of how long a path should be, so that if you try to use them on longer paths, they will explode in interesting ways. – dsolimano Jul 23 '10 at 15:37
  • Do Linux OS's have this problem? – ahorn Nov 29 '19 at 10:47
  • just for the record, on Win10 one can now remove that limitation - https://docs.microsoft.com/el-gr/archive/blogs/jeremykuhne/net-4-6-2-and-long-paths-on-windows-10 – George Birbilis Jul 01 '20 at 15:58

3 Answers3

21

According to Microsoft:

  • The traditional Windows API limits path names to 260 characters, even for applications developed for the latest version.

  • Applications using the Unicode-aware API can use a form of path that allows up to 32767 characters. The file name has to be prefixed with \\?\, and must be an absolute path, e.g., \\?\c:\dir\file or \\?\UNC\server\share\file. There are further limitations, see the reference for details.

If you've managed to create and use a deep file hierarchy and need to work with an application that bombs out because of file name length, there are a few things you can try:

  • Use the mklink command to create symbolic links, and pass a path that uses them to your application.

  • Use the subst command to assign a drive letter to a directory.

  • Start your application from a deep directory and pass it short relative paths.

  • Replace some long names by their 8.3 aliases (micros~1), assuming those still exist in Windows 7. If you have micros~1 alongside micros~2, I don't know how to tell which is which; perhaps run DOS command.com (again, assuming Windows 7 can still do it).

1

You could use the short (8.3) names for all your folders and files.

You need to make sure that they're enabled though.

A long file name is considered to be any file name that exceeds the short MS-DOS (also called 8.3) style naming convention. Typically, Windows stores long file names on disk as special directory entries, which can be disabled systemwide for performance reasons depending on the particular file system. When you create a long file name, Windows may also create a short 8.3 form of the name, called the 8.3 alias, and store it on disk also. This 8.3 aliasing can be disabled for a specified volume.

(my bold)

You'll also have to write some code to get the short name from the long name.

Source

ChrisF
  • 1,861
  • 1
  • 21
  • 28
  • 2
    lol... I can well remember these days in Windows 95 when we all got this super duper FAT32 with 256 chars long filenames! That was fantastic (at these days) and I'm really shocked that file name limitations could still be an issue in *these* days. 2010! Windows is really archaic... –  Jul 23 '10 at 14:25
  • Ten years after and still an issue. But when we know that this is a contract that cause very old Win32 Apps running today in windows 10 64 bits, **really archaic** may be changed for **what a trade-off** – Marcelo Scofano Diniz Dec 23 '20 at 20:15
0

The file/directory name in NTFS is limited to 255 unicode codepoints, since the length is stored as a byte. But there is no inherent limit of the total path length.

Many Win32 API calls (including explorer shell) calls do have the 260 - 1 length limit. Some other calls have the ability to use the \\?\ prefix to get up to 32K (a bit less, since the volume name gets substitued in Kernel-land)