TIL: Long Paths on Windows

It’s one of those issues, that when you run into it, you ask yourself, how this is still a thing in insert current year? How can Windows in 2024 still have problems dealing with file paths longer than 260 characters? …well actually 256 where three characters are taken up by the driver letter (e.g. C:\) and one character is used as NULL terminator. The answer is of course backwards compatibility – it’s always backwards compatibility with Windows.

NTFS does support long file paths for a very long time, but in order to access them, you’d have to prepend the magic string \\?\, or if you are a programmer, you can (or should?) use the Shell APIs for certain operations like enumerating files.

And if you’re not on a very old Windows 10 version – which you shouldn’t be, since that leaves you open for all sorts of vulnerabilities and Windows 10 is going out of support basically exactly in a year anyways – then you can enable long path support in the registry (or group policy). Which unfortunately isn’t the only step required, but you also need to enable it in the application manifest.

New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem" -Name "LongPathsEnabled" -Value 1 -PropertyType DWORD -Force
<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>

References

Leave a Comment

Your email address will not be published. Required fields are marked *

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.