Most Windows applications return the error Destination Path Too Long if the total length of the file path exceeds 260 characters when you try to copy, move, rename, create, or edit such a file. In this article, we will have a look at a few tricks that can help you to manage long file paths easily in Windows.
Table of Contents
Maximum File Path Length Limitations on Windows
The 260-character limit for the full file path is not a limitation of the NTFS file system, but of the Win32 API library. The Windows API always checks whether the path is longer than the MAX_PATH limit when you try to access a file.
When you use the Unicode API functions, it’s possible to use a path of up to 32767 characters in length. This allows many third-party applications (such as the popular file managers, for example FAR and Total Commander) to handle files/folders whose paths exceed 256 characters.
Note. Some programs use the UNC file path format (prefixed with “?”) to bypass the limitations of the Win32 API. For example, the absolute file path might look like this:
\\?\C:\folder1\subfolder1\toolongfilename
Due to max path length limitations, the administrator may encounter the following problems:
- Users can create files and folders in a shared network folder that the administrator cannot access locally;
- Errors when synchronizing roaming profiles;
- Errors in data recovery from shadow copies;
- Incorrect calculation of the directories size;
- File loss during migration, data transfer between servers, etc.
How to Fix the Destination Path Too Long on Windows
In our case, when we tried to move the file to a local directory on a computer running Windows 10, we got the following message:
Destination Path Too Long
The file name(s) would be too long for the destination folder. You can shorten the file name and try again, or try a location that has a shorter path.
Or:
An unexpected error is keeping you from copying the file.
Error 0x80010135: Path too long
Next, we will look at a few ways to solve or workaround the Windows long file path restriction.
Solution 1. Rename Parent Folder to Reduce Total File Path Length
The simplest way is to shorten the name of the parent folders, by reducing the total path length by simply renaming them. This workaround is not always applicable.
Solution 2. Create a Symbolic Link
Another option is to create a symbolic link to part of the path. This will shorten the total file path length.
To create a symbolic link to a folder with a long path, you can use the following command:
mklink /d c:\homelink “C:\verylongpathhere……”
Now you can perform all file operations (move, rename) on the directory to which the symbolic link is assigned (c:\homelink in our case). There are no restrictions on the maximum path length when you perform file operations against the symbolic link directory.
Solution 3. Use the SUBST Command to Overcome the Maximum Path Length
Another option is to map the problem folder to a virtual disk (in our example, Z:), using the built-in utility Subst. Thus, you can also shorten the path length:
Subst Z: “C:\verylongpathhere……”
Now you can work with the data on drive Z:, where the file path doesn’t exceed the Win32 API path limit. When the job is finished, you can delete the virtual disk using the Subst with the /d option:
Subst Z: /d
Solution 4. Bypass Long File Paths by Mapping a Folder to a Drive Letter
If you simply need to copy/move a lot of folders from one place to another, you can map the folder with the long path to a drive letter.
- You must open the destination folder by its UNC path. You need to browse the problem folder using the UNC path. This can be either the path to an SMB share, the path to an administrative share available on any Windows computer (for example, \\servername\d$\users\your_long_path…), or the NT file naming format (\\?\d:\users\longpath). Copy the folder path to the clipboard;
Note. The “\\?\” prefix tells Windows to stop further parsing of the path string and send the path after the prefix directly to the file system driver. In this case, you can bypass the Windows API restrictions and exceed the MAX_PATH limits.
- Open the File Explorer and select This PC. Click on the Map Network Drive button and select Map network drive;
- Paste your long folder path, select a drive letter you want to assign, and hit Finish;
- Now you can copy the files/folders to this location without the error.
Solution 5. Enable Win32 Long Path on Windows via Group Policy
Starting with Windows 10 version 1607 you can disable the MAX_PATH limit for manifested win32 and Windows Store apps. Long path support is disabled by default in Windows and can be enabled using the GPO editor.
Open the Local Group Policy Editor (Win + R > gpedit.msc > OK). Go to the following GPO section in the Group Policy editor: Computer Configuration > Administrative Templates > System > Filesystem. Enable the GPO option Enable Win32 long paths.
You can also enable long path support directly through the registry. Use the Regedit.exe editor to set the LongPathsEnabled parameter of REG_DWORD in the registry key HKLM\SYSTEM\CurrentControlSet\ControlFileSystem with a value 1.
You can change this registry parameter with the following PowerShell command:
Set-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem -Name LongPathsEnabled -Value 1
Reboot the computer to apply the changes.
Enabling Win32 long paths will allow manifested win32 applications and Windows Store applications to access paths beyond the normal 260 character limit.
Keep in mind, that to use the win32 NTFS long path, the application should be developed with this parameter enabled. As usual, such an option is enabled via the application manifest file. If the application is developed with NTFS long path support, then the longPathAware parameter must be added to the manifest file. For example:
<application xmlns=”urn:schemas-microsoft-com:asm.v3″>
<windowsSettings xmlns:ws2=”http://schemas.microsoft.com/SMI/2016/WindowsSettings”>
<ws2:longPathAware>true</ws2:longPathAware>
</windowsSettings>
</application>
In Visual Studio 2019 and MSBuild 16, this longPathAware parameter is enabled by default.
We would like to remind you that the LongPathsEnabled parameter allows you to bypass the path length restrictions only for Windows applications that were compiled without the MAX_PATH parameter. This means that Windows Explorer will not work with a long file path, even if the Win32 Long Paths policy setting is enabled. To manage files with a long path in File Explorer, you need to use one of the tricks described above.
Win32 Long Paths GPO Not Working on Windows 10 File Explorer
There is bad news. File Explorer even in the latest builds of Windows 10 20H2 and Windows Server 2019 still doesn’t support NTFS long paths. This means that when you open such a file/folder, you will still receive the error: “Destination Path Too Long”.
Windows Explorer does not have a declaration in the manifest, and you will have to use one of the tricks described in this article to access long paths in Windows.
We saw the following comment from a Microsoft employee:
This feature is not ready for inclusion in File Explorer. You need to wait until Microsoft turns it on in Explorer, or use a third-party file management tool that is compatible with long paths.
However, in some applications, the MAX_PATH check is embedded in the code. About the max file path restrictions for .Net developers, see Solution 7 below.
Solution 6. Using Robocopy Command Line Tool to Copy and Move Files
You can copy or move files, even with paths that exceed the limits, using the built-in console Windows tool robocopy.
For example, if you cannot delete the directory due to the path length limit, you can first move data from the directory using robocopy:
ROBOCOPY c:\folder1\folder2\folder3\longpath\ c:\tmp\ /MOVE /E
After that, you can delete the source folde:
Delete c:\folder1\folder2\folder3\longpath\ /q /f
Solution 7. Long File Path for .Net Developers
The Base Class Library (BCL) of the development environment for the .Net Framework has a built-in preliminary check for the admissibility of long directory and file names. Therefore .Net Framework developers may encounter a System.IO.PathTooLongException error in their programs.
Check for path length removed from BCL code in .Net Framework 4.6.2. Therefore, after updating the version of the .Net Framework, developers can use long paths in the UNC path format (\\?\C:\Very_long_path). When the LongPathsEnabled parameter is enabled in Windows 10/Windows Server 2016, it is possible to work correctly with files that have paths of almost any length.
To do this, use Net Framework 4.6.2 (and newer) when building applications, or use the following application configuration file for older app versions (.Net 4.0):
<?xml version=”1.0″ encoding=”utf-8″?>
<configuration>
<startup>
<supportedRuntime version=”v4.0″ sku=”.NETFramework,Version=v4.0″/>
</startup>
<runtime>
<AppContextSwitchOverrides value=”Switch.System.IO.UseLegacyPathHandling=false;Switch.System.IO.BlockLongPaths=false” />
</runtime>
</configuration>
Solution 8. Overcoming Long File Path in PowerShell
In order for the Get-Item, Get-ChildItem, Remove-Item, and other PowerShell cmdlets to work correctly with long file paths, you need to upgrade the .NET Framework to 4.5 or newer and install Windows Management Framework 5.1.
Tip. The current version of PowerShell can be found in the variable $PSVersionTable.
After that, when using file cmdlets instead of Path, you need to use the LiteralPath parameter. For example:
Get-ChildItem -literalpath \\?\C:\PS
Solution 9. Use 7-Zip to Perform File Operation with Long File Paths
To bypass the MAX_PATH restriction in Windows, you can use the popular 7ZIP archiver. Install 7-Zip, run the 7zFM.exe app, and paste the path to the problem folder into the address bar.
You can now perform any file operations on the files in this directory from the 7-Zip File Manager GUI. 7-Zip ignores Win32API restrictions on max path lengths.
Notes:
- There also is a great tool called “Long Path Tool” that works great to fix this. However it isn’t free, the methods above are.
- Thank you, Colin Albright, for the comment below. Yes, you can also use 7-zip or any zip utility to fix the Destination Path Too Long problem. Sometimes on single files, this could be a better and faster solution. Just zip the folder up, and you are good to go.
4 comments
The real question is why such a ridiculous shortcoming was implemented in Windows to begin with — the whole point of filenames and pathnames is to structure and label data sufficiently to be human-understandable. Limiting pathnames has ALWAYS been unacceptable is is shameful for MicroSoft to have done.
One workaround I used is running an Android file manager like Root Explorer, etc and make a SAMBA connection to the Windows 10 computer. Then, from the Android file manager, I can rename any Latin and/or Unicode file names that is longer than the 255 characters’ limitation – issue exhibited by Window Explorer. Android is built on top of Linux so it doesn’t have this limitation like the Windows Explorer application in Windows 10!
Another solution would be to install an Android emulator for Windows like Bluestacks, etc and run an Android file manager like Root Explorer, etc and rename Windows’ files with long names without any problems with file name’s length. Again, Android/Linux comes to the rescue!
@Mike: No, the solution suggested will only work for Windows applications that don’t specify the MAX_PATH variable in the programming codes, which is limited to 255 Latin characters, like Windows Explorer! So, Windows Explorer will NEVER work despite the registry’s mod and the group policy’s mod.
The workaround that doesn’t cost you a dime if you use Android/Linux is:
1. Root Explorer (Android free application)
2. BlueStacks (Android free emulator for Windows)
3. Any Android device that supports SAMBA network connection.
One workaround I used is running an Android file manager like Root Explorer, etc and make a SAMBA share/connection to the Windows 10 computer. Then, from the Android file manager, I can rename any Latin and/or Unicode file names via the SAMBA share, without suffering the file’s limitation issue exhibited by Windows Explorer itself!
Another solution would be to install an Android emulator for Windows like Bluestacks, etc and run an Android file manager like Root Explorer, etc and rename Windows’ files with long names without any problems with file name’s length. Again, Android/Linux comes to the rescue!
It is located here
Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem
for me
Comments are closed.