In Windows the default total path length must not exceed 260 characters (drive
+ :\
+ 255 characters of filename
+ null terminator
+ probably for final \
in case the path is a directory or simply for even rounding). It was a relic from DOS's 8.3-name era where a 260-character path is a really deep path.
It's possible that your path to the folder was already very long, so the remaining part for your filename is just 129. If you want longer path, you have several solutions:
- use fully qualified file names with
\\?\
prefix, this way you can use maximum 32767 characters in the path‡ - rename the folders in the path to make it shorter
- mount the folder containing the file into a drive character with
subst
/mountvol
/New-PSDrive
/diskmgmt.msc. This way you can use the maximum 255 characters for your file name - create a junction/symbolic link to another shallower folder on the path. You can't create links to drive letters, hence you can't achieve filenames as long as if you've used the mounting method
Since Windows 10 there's another option by removing MAX_PATH limitation§. You can enable it by setting HKLM\SYSTEM\CurrentControlSet\Control\FileSystem LongPathsEnabled
in registry or set Computer Configuration > Administrative Templates > System > Filesystem > Enable NTFS long paths in group policy
Note that folders have a different limit. If you make a new folder in PowerShell or .NET that has very long name you'll get the below error
The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.
That's because it "allows for 248 characters for the path plus the filename which allows for 12 characters."
MAX_PATH, which limits file paths to a paltry 259 characters (sans the terminating null); the current directory to 258 characters (sans a trailing backslash and null); and the path of a new directory to 247 characters (subtract 12 from 259 to leave space for an 8.3 filename).
The maximum length of the path of a file: 259 or 258 characters?
Read more:
- Why does the 260 character path length limit exist in Windows?
- MSDN - Naming Files, Paths, and Namespaces
‡The maximum path of 32,767 characters is approximate, because the
\\?\
prefix may be expanded to a longer string by the system at run time, and this expansion applies to the total length.§Starting in Windows 10, version 1607,
MAX_PATH
limitations have been removed from common Win32 file and directory functions. However, you must opt-in to the new behavior.