File names are limited to 255 UTF-16 code points. 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 points. There are some additional restrictions on code points and file names.
In the Windows API (with some exceptions discussed in the following paragraphs), the maximum length for a path is MAX_PATH, which is defined as 260 characters.
Windows API 里面定义了一个常量 MAX_PATH,这个常量的值是 260,不过常量值不一定是具体的长度,继续向下看,文档里面有一个例子
For example, the maximum path on drive D is "D:\some 256-character path string"
When using an API to create a directory, the specified path cannot be so long that you cannot append an 8.3 file name (that is, the directory name cannot exceed MAX_PATH minus 12).
新技能√
以后片子又有新的方法存了。谢谢 @eccstartup
NTFS:
我刚才试了一下,在
E:\data
目录建了一个长度为 239 的成功了。长度为 240 的失败了
当我进入子目录(239长度的那个),再新建一个长度为 1 的,失败。
至此,晕了。
看看 NTFS 的百科:http://en.wikipedia.org/wiki/NTFS#Internals
这里面有一句:There are some additional restrictions on code points and file names,我们跟随链接 "Naming Files, Paths, and Namespaces"
Windows API 里面定义了一个常量
MAX_PATH
,这个常量的值是 260,不过常量值不一定是具体的长度,继续向下看,文档里面有一个例子好吧,那就试试
删除一个字符,再试,删除,再试,…… 最后终于可以了,目录长度 244,啊,你是 MSDN 请来的逗比吗?
不能着急,继续往下看
留坑吧,一会儿继续填。