To enable long file path names in Windows 11, you can follow the same steps as in Windows 10. Starting in Windows 10, version 1607, MAX_PATH limitations have been removed from common Win32 file and directory functions, but you must opt-in to the new behavior. To enable the new long path behavior, both of the following conditions must be met:
- The registry key
Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem\LongPathsEnabled (Type: REG_DWORD)
must exist and be set to 1. - The application manifest must also include the
longPathAware
element.
You can also copy the code to a .reg
file which can set this for you, or use the PowerShell command from a terminal window with elevated privileges. Once this feature is enabled, you must access the SMB share needs using \\?\
in the path to allow longer path lengths. This method doesn't support UNC paths, so the SMB share needs to be mapped to a drive letter.
Here are the directory management functions that no longer have MAX_PATH restrictions if you opt-in to long path behavior: CreateDirectoryW, CreateDirectoryExW GetCurrentDirectoryW RemoveDirectoryW SetCurrentDirectoryW. These are the file management functions that no longer have MAX_PATH restrictions if you opt-in to long path behavior: CopyFileW, CopyFile2, CopyFileExW, CreateFileW, CreateFile2, CreateHardLinkW, CreateSymbolicLinkW, DeleteFileW, FindFirstFileW, FindFirstFileExW, FindNextFileW, GetFileAttributesW, GetFileAttributesExW, SetFileAttributesW, GetFullPathNameW, GetLongPathNameW, MoveFileW, MoveFileExW, MoveFileWithProgressW, ReplaceFileW, SearchPathW, FindFirstFileNameW, FindNextFileNameW, FindFirstStreamW, FindNextStreamW, GetCompressedFileSizeW, GetFinalPathNameByHandleW.
References: