TL;DR
PowerShell as administrator:
| |
Reboot (or at least restart the affected programs). Through Group Policy, the same under Computer Configuration → Administrative Templates → System → Filesystem → Enable Win32 long paths.
With that, programs that declare themselves compatible stop failing on paths over 260 characters. The ones that do not stay the same: for those, the \\?\ prefix, subst, or robocopy.
The problem
| |
MAX_PATH is 260 characters including the drive letter and the trailing NUL. It is easy to hit with node_modules, git clones with long names, backups that nest folders, or a sync that brings a deep structure from another system.
What the value does
Since Windows 10 1607 (and Server 2016), many Win32 file functions (CreateFileW, CopyFileW, MoveFileW, FindFirstFileW, CreateDirectoryW…) accept paths up to about 32,767 characters if two conditions hold:
LongPathsEnabled = 1in the registry (or the policy).- The program declares
longPathAwarein its manifest.
Windows reads the value once per process, on the first call to those functions. Hence the reboot: processes that were already running (Explorer, services) keep the old value.
| Program | Honors long paths with the value on? |
|---|---|
| PowerShell 7 | Yes |
| Windows PowerShell 5.1 | Partially; depends on the cmdlet |
| .NET (Core) and modern apps | Yes |
| Git for Windows | Yes, with git config --system core.longpaths true |
robocopy, 7-Zip | Yes (they use \\?\ on their own, value or not) |
cmd.exe (dir, copy, del) | No |
| File Explorer | Partial; still trips when copying or deleting |
| Old applications | No, and there is no way to force them |
Check the value:
| |
Quick test in PowerShell 7:
| |
Plan B when the program will not cooperate
The
\\?\prefix: tells Windows to pass the path as is, without the limit. Works on any version with no registry change, but only with absolute paths and no./... For UNC:\\?\UNC\server\share\....1 2dir \\?\C:\projects\very\deep rd /s /q \\?\C:\projects\very\deep\node_modulesShorten the path:
subst X: C:\projects\very\deepcreates a drive that starts from zero;net usedoes the same with UNC paths.Delete what nobody can delete:
robocopy C:\empty C:\impossible\path /MIRwith an empty folder leaves the target empty and then it can be removed.Git:
core.longpaths trueand, on Windows, clone near the root (C:\src\repo) instead of insideDocuments.
Traps
- The value is not a global switch. It is a permission each program has to claim; enabling it breaks nothing, but it does not fix programs that do not ask for it either.
- Reboot. Without it, Explorer and services keep the cached value.
- Component names: each folder or file is still limited to 255 characters; what grows is the total.
- Relative paths are always limited to 260, value or not.
- Backwards compatibility: a file created on a long path may not open from an old program on the same machine. If you share folders with legacy software, keep paths short.
Bonus: test files of an exact size
To test transfers, quotas, or space without hunting for a big file:
| |
It instantly creates a file of the given size in bytes without writing data (it reads as zeros). The upside is that it is instant even for 50 GB; the downside is that it compresses to nothing, so it is useless for measuring compression or deduplication performance.
Reference: Maximum Path Length Limitation on Microsoft Learn.