Friday, September 1, 2017

How do "Path Too Long" get created in the first place?

Microsoft has a core set of application programming interfaces (APIs) that programmers can use to interact with applications in the Windows operating system. These programming interfaces are often referred to as the Windows API. The Windows API hard-coded a maximum filename length called MAX_PATH such that a filename, including the file path to get to the file, can't exceed 260 characters. 

A path must meet this criterion;  

a+b.txt<=260 characters  
1.The fully qualified filename with extension (b) must be less than 260 characters. ie filename.txt
2.The directory name (a) must be less than 248 characters. ie c:\dir1\dir2
3. Combined a+b must be less than 260 characters.  
Windows Explorer is build using the Windows API, and will fail when copying long paths.

Windows Explorer, now renamed File Explorer in Windows 10+ will fail when copying long paths.



New: Windows 10 and 10 CU tried to address this, with a registry setting to support  "Long Paths" but, File Explorer still fails.





Registry setting 

1
2
HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\FileSystem]
"LongPathsEnabled"=dword:00000001


However, because this is a limitation of the Windows API and not the file system used on the majority of Windows installations (NTFS), some programs can create filenames that violate this limit.


How are Paths Too Long created?


Programs such as MS-DOS, torrents, unzip programs can overcome this.
mkdir "\\?\C:\very long path" in the command shell, for example.

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 \\?\, as example above.

Most commonly is if you copy files or back-up a hard-drive or USB from another system.


If you share/mount a NTFS disk from a Mac or Linux system can run into paths that are too long, since those systems do support paths that are too long.




Online Backups will fail





Back-ups to the cloud providers such as Onedrive, Gdrive and DropBox will fail with path too long errors as well. You may not even see the errors if you don't check the logs, which most users do not.



How to automatically fix Paths Too Long ?


Path Too Long Auto Fixer is the 1st tool of it's kind to automatically fix paths that are too long.


Path Tool Long Auto Fixer tool will find all directories and filenames that are too long and auto correct them! Make sure your next back-up does not fail.

Download free demo at https://pathtoolongautofixer.blogspot.com

Preview

Maximum Path Length Limitation - Details


In the Windows API (with some exceptions discussed in the following paragraphs), the maximum length for a path is MAX_PATH, which is defined as 260 characters. A local path is structured in the following order: drive letter, colon, backslash, name components separated by backslashes, and a terminating null character. For example, the maximum path on drive D is "D:\some 256-character path string" where "" represents the invisible terminating null character for the current system codepage. (The characters < > are used here for visual clarity and cannot be part of a valid path string.)
Note  File I/O functions in the Windows API convert "/" to "\" as part of converting the name to an NT-style name, except when using the "\\?\" prefix as detailed in the following sections.
The Windows API has many functions that also have Unicode versions to permit an extended-length path for a maximum total path length of 32,767 characters. This type of path is composed of components separated by backslashes, each up to the value returned in the lpMaximumComponentLength parameter of the GetVolumeInformation function (this value is commonly 255 characters). To specify an extended-length path, use the "\\?\" prefix. For example, "\\?\D:\very long path".

Note  The maximum path of 32,767 characters is approximate, because the "\\?\" prefix may be expanded to a longer string by the system at run time, and this expansion applies to the total length.

The "\\?\" prefix can also be used with paths constructed according to the universal naming convention (UNC). To specify such a path using UNC, use the "\\?\UNC\" prefix. For example, "\\?\UNC\server\share", where "server" is the name of the computer and "share" is the name of the shared folder. These prefixes are not used as part of the path itself. They indicate that the path should be passed to the system with minimal modification, which means that you cannot use forward slashes to represent path separators, or a period to represent the current directory, or double dots to represent the parent directory. Because you cannot use the "\\?\" prefix with a relative path, relative paths are always limited to a total of MAX_PATHcharacters.


No comments:

Post a Comment