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.
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 havemicros~1
alongsidemicros~2
, I don't know how to tell which is which; perhaps run DOScommand.com
(again, assuming Windows 7 can still do it).You could use the short (8.3) names for all your folders and files.
You need to make sure that they're enabled though.
(my bold)
You'll also have to write some code to get the short name from the long name.
Source
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)