Maximum path-length or filename sizes on Windows

November 5, 2008

MSDOS could understand 8.3 file names only where 8 characters were reserved for filename and 3 for the extension. But Windows NT onwards Windows applications can create or manipulate path lengths of 260 characters, where 259 are actual characters + 1 NULL character. Moreover out of 259 characters, only 256 characters can be used for each component in the path.

C:\<256 character length><NULL>

NTFS actually can actually support 32767 characters in the paths. To handle this in your application, you must use unicode versions of file APIs such as CreateFileW etc and also prepend “\\?\” to the file paths. This tells the APIs to not to enforce 260 character limit.

To handle 32k long paths from the command line prepend “\\?\” to the paths. For e.g. to copy a file from drive c: to drive d: enter the following statement on the command prompt.

copy “\\?\c:\temp\<Long Path>” “\\?\d:\temp\<Another Long Path>”

Advertisements