Is there any length-limits of file path in NTFS?

user25749 picture user25749 · Dec 7, 2009 · Viewed 15.8k times · Source

Why can not I create a deep path whose characters in path is more than 255 in NTFS File System? It seems a limits of FAT32, but also exist in NTFS? Can anyone provide some documents?

Many Thanks!

Answer

Matt Dotson picture Matt Dotson · Dec 7, 2009

The 260 character limitation is not a limitation of the file system, but of the Win32 API. Win32 defines MAX_PATH as 260 which is what the API is using to check the length of the path passed into functions like FileCreate, FileOpen, etc. (which are used by .NET in the BCL).

However, you can bypass the Win32 rules and create paths up to 32K characters. Basically you need to use the "\\?\C:\MyReallyLongPath\File.txt" syntax which you may not have seen before. Last I checked, the File and FileInfo classes in .NET prevented you from using this type of path, but you can definitely do it from C/C++. Here's a link for more info.

http://msdn.microsoft.com/en-us/library/aa365247(VS.85).aspx