TL;DR

PowerShell as administrator:

1
2
New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem" `
  -Name "LongPathsEnabled" -Value 1 -PropertyType DWORD -Force

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

1
2
3
The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters.
error: unable to create file ...: Filename too long          # git
System.IO.PathTooLongException                              # .NET

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:

  1. LongPathsEnabled = 1 in the registry (or the policy).
  2. The program declares longPathAware in 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.

ProgramHonors long paths with the value on?
PowerShell 7Yes
Windows PowerShell 5.1Partially; depends on the cmdlet
.NET (Core) and modern appsYes
Git for WindowsYes, with git config --system core.longpaths true
robocopy, 7-ZipYes (they use \\?\ on their own, value or not)
cmd.exe (dir, copy, del)No
File ExplorerPartial; still trips when copying or deleting
Old applicationsNo, and there is no way to force them

Check the value:

1
Get-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem" -Name LongPathsEnabled

Quick test in PowerShell 7:

1
2
3
4
$p = "C:\t\" + ("a" * 200) + "\" + ("b" * 100)
New-Item -ItemType Directory -Path $p -Force | Out-Null
Get-ChildItem "C:\t" -Recurse | Measure-Object
Remove-Item "C:\t" -Recurse -Force

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
    2
    
    dir \\?\C:\projects\very\deep
    rd /s /q \\?\C:\projects\very\deep\node_modules
    
  • Shorten the path: subst X: C:\projects\very\deep creates a drive that starts from zero; net use does the same with UNC paths.

  • Delete what nobody can delete: robocopy C:\empty C:\impossible\path /MIR with an empty folder leaves the target empty and then it can be removed.

  • Git: core.longpaths true and, on Windows, clone near the root (C:\src\repo) instead of inside Documents.

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:

1
2
fsutil file createnew C:\temp\dummy-1G.bin 1073741824
fsutil file createnew C:\temp\dummy-100M.bin 104857600

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.