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

前端 未结 3 1421
天涯浪人
天涯浪人 2021-02-05 11:41

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 docum

相关标签:
3条回答
  • 2021-02-05 11:59

    Quoted from wikipedia

    File names are limited to 255 UTF-16 code words. Certain names are reserved in the volume root directory and cannot be used for files. These are: $MFT, $MFTMirr, $LogFile, $Volume, $AttrDef, . (dot), $Bitmap, $Boot, $BadClus, $Secure, $Upcase, and $Extend;[3] . (dot) and $Extend are both directories; the others are files. The NT kernel limits full paths to 32,767 UTF-16 code words.

    http://en.wikipedia.org/wiki/NTFS

    0 讨论(0)
  • 2021-02-05 12:06

    Doc. You should certainly be able to create longer filepaths than 255 bytes, as long as each individual path component is under that. However you must be using the Unicode (W) versions of the file access calls to get this behaviour; if you're using the ANSI (A) byte-based interfaces such as those used by stdio, you'll be stuck with the limitations of the old pre-Unicode path interface.

    0 讨论(0)
  • 2021-02-05 12:07

    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

    0 讨论(0)
提交回复
热议问题