🐍 Python 3.10+

Enable Win32 Long Paths (Python)

Lifts the legacy 260-character MAX_PATH limit for apps that opt in (requires admin). Requires an elevated (Administrator) prompt. Applies the tweak via the stdlib winreg module.

By WindowsScripting.com · 617 B
set_enable_long_paths.py
#!/usr/bin/env python3
"""
set_enable_long_paths.py

Enable Win32 Long Paths.
Lifts the legacy 260-character MAX_PATH limit for apps that opt in (requires admin). Requires an elevated (Administrator) prompt.

Usage:
    python set_enable_long_paths.py
"""

import winreg


def main() -> None:
    key = winreg.CreateKeyEx(
        winreg.HKEY_LOCAL_MACHINE, r"SYSTEM\CurrentControlSet\Control\FileSystem", 0, winreg.KEY_SET_VALUE
    )
    winreg.SetValueEx(key, "LongPathsEnabled", 0, winreg.REG_DWORD, 1)
    winreg.CloseKey(key)
    print("Enable Win32 Long Paths applied.")


if __name__ == "__main__":
    main()