window、linux、mac 文件路径禁止字符, 路径长度【全网总结】 您所在的位置:网站首页 mac文件包括 window、linux、mac 文件路径禁止字符, 路径长度【全网总结】

window、linux、mac 文件路径禁止字符, 路径长度【全网总结】

#window、linux、mac 文件路径禁止字符, 路径长度【全网总结】| 来源: 网络整理| 查看: 265

参考: https://9to5answer.com/what-characters-are-forbidden-in-windows-and-linux-directory-names https://www.codenong.com/1976007/#码农翻译快照#Windows和Linux目录名中禁止使用哪些字符? https://ispacesoft.com/64457.html#各种系统路径和文件名长度的最大限制 https://learn.microsoft.com/zh-cn/windows/win32/fileio/maximum-file-path-limitation#最大路径长度限制 https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-fscc/18e63b13-ba43-4f5f-a5b7-11e871b71f14#8.3文件名规则 https://www.autohotkey.com/boards/viewtopic.php?t=86131#@iPhilip drive letter + :\ + 243 folder name characters + \ + 12 file name characters 【大小写敏感】 Windows: no Linux/Unix:yes MacOS: yes MacOSX: no 【同级目录下允许存在同名文件与目录】 Windows: no 万事总有例外,如: Windows 11 桌面隐藏两个同名文件 "Desktop.ini" 使用其它 Hacker 手段也可能创建同名文件。 【文件名禁止字符】 这里讲的是正常使用情况下的禁止规则,排除使用其它 Hacker 手段添加的禁止字符。 Windows: 1.文件路径(包括驱动器号、目录名、文件名)不区分大小写。 2.被禁可打印ASCII字符是: \ / : * ? " < > | \ (backslash,可作为路径分隔符,将一个目录名与路径中的另一个目录名称分开) / (forward slash) : (colon - sometimes works, but is actually NTFS Alternate Data Streams,作为驱动器号与目录路径的分隔符) * (asterisk) ? (question mark) " (double quote) < (less than) > (greater than) | (vertical bar or pipe) 3.不可打印字符 如果您的数据来自允许不可打印字符的源,那么还需要检查更多。 0-31 (ASCII control characters,控制字符) 4.保留文件名(包含小写) AUX, CON, CONIN$, CONOUT$, NUL, PRN COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9 LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, LPT9 但加上任意的文件扩展名则符合规则,例如,LPT1.txt。 只加一个点号和/或空格可不行,如: CON. 或 CON . 【自测 Win10】 CONIN $,CONOUT $ CONIN(或CONOUT)+空格+$ 是合法文件名。 CONIN$, CONOUT$ 也被保留。试图创建则提示是“无效的文件句柄”。 "CONIN$" 和 "CONOUT$" 也是保留字。 与 "CON" 不同,它们允许以读写方式访问控制台输入和屏幕缓冲区。 在 Windows 8 之前,只有基本文件名是保留的。 从 Windows 8 开始,底层的控制台 IPC 被重新设计为使用设备驱动程序, 因此这两个名称现在被通用地作为 DOS 设备处理,与 "NUL" 等相同。 这意味着它们可以用于本地设备路径,例如 "\\.\CONIN$" 和 "\\?\CONOUT$" , 且还意味着 API 假装这些名称在每个现有目录中都 '存在' 。例如,"C:\Temp\CONOUT$" 引用控制台输出。 【DOS设备名称】 请注意,保留的 DOS 设备名称和文件名以点或空格结尾的规则是在将 DOS 路径转换为本地 NT 路径时由运行时库应用的。 如果路径以 "\\?\" 本地设备前缀开头,则跳过这个规范化步骤,除了用 NT 的 "\??\" 设备前缀替换 "\\?\" 。 这个前缀指示对象管理器在登录会话和全局 DOS 设备目录中搜索一个符号链接, 该符号链接指向一个本地 NT 设备,通常是 "\Device" 目录中的一个设备对象。 【LPT1...9】 使用 Cygwin,您可以轻松创建 lpt1 和 lpt1.txt 等类似设备名。 【不可打印字符】 把 TAB 等字符粘贴进 Cygwin Bash, 可以用它在 Windows 下创建含有特殊字符的文件名。 ls -l 查看显示为 '$'\t 这其实是一个字符,并非两个字符。 5.文件名不能以空格开头或结尾 Windows 自动去除开头和结尾的连续空格。 6.文件名不能以英文点号结尾 - Windows 自动去除结尾的连续点号 ‘.’ - 使用句点作为路径中的目录部分来表示当前目录,例如 ".\\temp.txt" - 使用两个连续的句点 (..) 作为路径中的目录 组件 来表示父目录,例如 "..\\temp.txt" 因此包括但不止下列文件名均不合法: . .. ... .... " ...." 这里要去除双引号,只为表示前面有一个空格 ".... " 这里要去除双引号,只为表示后面有一个空格 ... . ... 7.其他规则 DOS中, 不允许使用 - (hyphen, 连字符) FAT、exFAT 格式禁止 ^ "CONIN$", "CONOUT$" 8.文件路径长度限制 - 不开启长文件名 Windows 默认不开启长文件名,系统路径的限制长度是 260,文件名的长度最大不超过 255. 在头文件 stdlib.h 中定义 #define MAX_PATH 260 实际的文件名必须少于 260,因为完整路径(如 C:\Program Files\filename.txt)都包含在此字符数值中。 另外末尾要保留一个字节 (GBK) 或两个字节 (UNICODE) 给结束符 (null, 即 \0)。 - 开启长文件名 Windows 开启长文件名时,系统路径的限制长度是 32767,文件名的长度最大不超过 255. 从 Windows 10 version 1607 build 14352 之后,就可以设置启用 enable NTFS long paths 来打破路径最大长度是 260 的限制。 开启的方法是:打开注册表,修改 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem] "LongPathsEnabled"=dword:00000001 - 在命令文件时,windows会截断文件名超出长度的部分。 - 在脚本中,文件路径首尾各一个双引号不算在长度内。 - 关于一个汉字占用两个字节,可能与 GBK(GB2312等) 和 UNICODE(UTF-8等) 编码有关。 一个中文字符,GBK: 1; UNICODE: 2 个字节。 - UNC(Universal Naming Convention),即“通用命名约定”。 如果文件路径采用 UNC 规则, 一些前缀不用作路径本身的一部分。如: \\?\UNC\server\share 其中“server”是计算机的名称,“share”是共享文件夹的名称。这些前缀不用作路径本身的一部分。它们指示路径应以最少的修改传递到系统, 这意味着您不能使用正斜杠来表示路径分隔符,也不能使用句点来表示当前目录,也不能使用双点来表示父目录。 由于不能将“\\?\”前缀与相对路径一起使用,因此相对路径始终限制为总共 MAX_PATH(包括 \0) 个字符。 - 另外,文件名命名规则有些需要继承 DOS 8.3 命名规则,参考 【@iPhilip 实测】 参考文章末尾的讲解。 【我的实测 Windows 11 中文简体】 文件完整路径最多包含 247 个字符,可能 Windows 8.3 API 有关,下面引自 MSDN 原话: 使用 Windows file I/O API 创建目录时,指定的路径不能太长,以至于无法追加 8.3 文件名(即目录名不能超过 MAX_PATH 减 12)。 合法最长例子: C:\2441111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111 C:\35111111111111111111111111111111111\2081111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111 C:\35111111111111111111111111111111111\204111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111.txt C:\31中文11111111111111111111111111111\204111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111.txt C:\31中文11111111111111111111111111111\20611111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111.txt 注:上面文件完整路径是 3+33+1+206 个字符+4=247, 说明一个中文文字只占一个字符。 把最长命名的文件移动到比当前目录长度更长的目录路径中,不会报错,不会修改文件名。 这时再读取这个文件时会出错,但可使用短文件名路径访问,如: type "C:\244111~1\111111~1" Linux/Unix: 1.被禁可打印ASCII字符是 / (forward slash) 注: Linux/Unix文件名具有控制字符是合法的,对用户来说,处理这些文件可能是一场噩梦。。 最好文件名中不要包含 : ? @ # $&()|; ‘’“”等字符,另外 空格符,制表符和退格符也不建议使用。 避免使用 + - 和. 作为文件名的第一个字符(Linux下以.开头的文件是隐藏文件)。 2.不可打印字符 \0 (NULL byte) 3.文件路径长度限制 limits.h 头文件里面有针对 NAME 和 PATH 的最大长度限制: #define NAME_MAX 255 /* # chars in a file name */ #define PATH_MAX 4096 /* # chars in a path name including nul */ 完整路径: 4096 字节; 文件名: 255 字节。 MacOS HFS+: 1.被禁可打印ASCII字符是: : (colon 英文冒号被禁, 中文冒号:可以) 2.其他规则 . (dot 英文点号不能放在文件名开头, 中文句号‘。’可以) 3.文件路径长度限制 syslimits.h 头文件里面有针对 NAME 和 PATH 的最大长度限制: #define NAME_MAX 255 /* # max bytes in a file name */ #define PATH_MAX 1024 /* # max bytes in pathname */ 完整路径: 1024 字节; 文件名: 255 字节。 :: --------------------------------------------------------------------------------------------------------------------- https://www.autohotkey.com/boards/viewtopic.php?t=86131 https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-fscc/18e63b13-ba43-4f5f-a5b7-11e871b71f14 【@iPhilip 实测】 I did some tests with the script below and I can make the following observations: 我用下面的脚本做了一些测试,我可以做出以下观察: The maximum number of characters in a path is 259 (MAX_PATH - 1). 路径中的最大字符数为 259 (MAX_PATH - 1)。 The maximum number of characters in a file name is 255, e.g. drive letter + :\ + 255 file name characters. 文件名中的最大字符数为 255,例如驱动器号 + :\ + 255 个文件名字符。 The maximum number of characters in a folder name is 244, e.g. drive letter + :\ + 244 folder name characters. 文件夹名称中的最大字符数为 244,例如驱动器号 + :\ + 244 个文件夹名称字符。 When combined with a backlash and a file name the maximum number of characters in a folder name is 243, e.g. drive letter + :\ + 243 folder name characters + \ + 12 file name characters. The 12 characters represent the number of characters in an 8.3 file name. This is consistent with the following statement from the Maximum Path Length Limitation page: 当与反斜杠和文件名结合使用时,文件夹名称中的最大字符数为 243,例如驱动器号 + :\ + 243 个文件夹名称字符 + \ + 12 个文件名字符。 这 12 个字符表示 8.3 文件名中的字符数。 8 个基本文件名字符 + . + 最多 3 个扩展名字符。 The base filename MUST be 1-8 characters in length and MUST NOT contain a "." period character. 基本文件名的长度必须为 1-8 个字符,并且不得包含“.”句点字符。 The filename extension, if present, MUST be 1-3 characters in length and MUST NOT contain a "." period character. 文件扩展名(如果存在)长度必须为 1-3 个字符,并且不得包含“.”句点字符。 这与“最大路径长度限制”页中的以下语句一致: 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). 使用 API 创建目录时,指定的路径不能太长,以至于无法追加 8.3 文件名(即目录名不能超过 MAX_PATH 减 12)。 Here is the script: 这是脚本: #NoEnv ; Admin priviledges are required to create files and/or folders in the root directory full_command_line := DllCall("GetCommandLine", "str") if not (A_IsAdmin or RegExMatch(full_command_line, " /restart(?!\S)")) { try { if A_IsCompiled Run *RunAs "%A_ScriptFullPath%" /restart else Run *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%" } ExitApp } MAX_PATH := 260 ; Test of longest path in the script directory Loop { MaxChars := MAX_PATH - A_Index LongPath := A_ScriptDir "\" NoChars := StrLen(LongPath) Loop, % MaxChars - NoChars - 4 LongPath .= "x" LongPath .= ".txt" FileAppend, , % LongPath if FileExist(LongPath) break } MsgBox % "The file path has " StrLen(LongPath) " characters.`nThe file name has " StrLen(LongPath) - NoChars " characters.`nThe first 25 characters are: " SubStr(LongPath, 1, 25) "`nThe last 25 characters are: " SubStr(LongPath, -24) "`n`nClick OK to delete it." FileDelete, % LongPath ; Test of the longest filename in the C:\ folder Loop { MaxChars := MAX_PATH - A_Index LongPath := "C:\" NoChars := StrLen(LongPath) Loop, % MaxChars - NoChars - 4 LongPath .= "x" LongPath .= ".txt" FileAppend, , % LongPath if FileExist(LongPath) break } MsgBox % "The file path has " StrLen(LongPath) " characters.`nThe file name has " StrLen(LongPath) - NoChars " characters.`nThe first 25 characters are: " SubStr(LongPath, 1, 25) "`nThe last 25 characters are: " SubStr(LongPath, -24) "`n`nClick OK to delete it." FileDelete, % LongPath ; Test of the longest folder in the C:\ folder Loop { MaxChars := MAX_PATH - A_Index LongPath := "C:\" NoChars := StrLen(LongPath) Loop, % MaxChars - NoChars LongPath .= "x" FileCreateDir, % LongPath if FileExist(LongPath) break } MsgBox % "The folder path has " StrLen(LongPath) " characters.`nThe folder name has " StrLen(LongPath) - NoChars " characters.`nThe first 25 characters are: " SubStr(LongPath, 1, 25) "`nThe last 25 characters are: " SubStr(LongPath, -24) "`n`nClick OK to delete it." FileRemoveDir, % LongPath ; Test of the longest folder + 8.3 file name in the C:\ folder Loop { MaxChars := MAX_PATH - A_Index LongPath := "C:\" NoChars := StrLen(LongPath) Loop, % MaxChars - NoChars - 13 ; StrLen("\") + 8 + 1 + 3 (8.3 file) = 13 LongPath .= "x" LongPath .= "\" FileCreateDir, % LongPath Folder := LongPath LongPath .= "12345678.123" FileAppend, , % LongPath if FileExist(LongPath) break } MsgBox % "The folder path has " StrLen(LongPath) " characters.`nThe folder name has " StrLen(Folder) - NoChars - 1 " characters.`nThe first 25 characters are: " SubStr(LongPath, 1, 25) "`nThe last 25 characters are: " SubStr(LongPath, -24) "`n`nClick OK to delete it." FileDelete, % LongPath FileRemoveDir, % Folder ExitApp Thus, the statement in the Long Paths section of the documentation is partially correct in that a single file name, but not a folder name, has a maximum length of 255 characters. I modified my original post to reflect the above observations. 因此,文档的“长路径”部分中的语句部分正确,因为单个文件名(而不是文件夹名称)的最大长度为 255 个字符。 我修改了我的原始帖子以反映上述观察结果。 :: ---------------------------------------------------------------------------------------------------------------------

目录

【参考:】

【大小写敏感】

【同级目录下允许存在同名文件与目录】

【文件名禁止字符】

 Windows:  

 Linux/Unix:

 MacOS HFS+:

【@iPhilip 实测】

Here is the script:  这是脚本:

【参考:】

https://9to5answer.com/what-characters-are-forbidden-in-windows-and-linux-directory-names https://www.codenong.com/1976007/#码农翻译快照#Windows和Linux目录名中禁止使用哪些字符? https://ispacesoft.com/64457.html#各种系统路径和文件名长度的最大限制 https://learn.microsoft.com/zh-cn/windows/win32/fileio/maximum-file-path-limitation#最大路径长度限制 https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-fscc/18e63b13-ba43-4f5f-a5b7-11e871b71f14#8.3文件名规则 https://www.autohotkey.com/boards/viewtopic.php?t=86131#@iPhilip  drive letter + :\ + 243 folder name characters + \ + 12 file name characters

【大小写敏感】

Windows:    no  Linux/Unix:yes  MacOS:      yes  MacOSX:     no

【同级目录下允许存在同名文件与目录】

 Windows:     no               万事总有例外,如: Windows 11 桌面隐藏两个同名文件 "Desktop.ini"               使用其它 Hacker 手段也可能创建同名文件。

【文件名禁止字符】

 这里讲的是正常使用情况下的禁止规则,排除使用其它 Hacker 手段添加的禁止字符。

 Windows:  

  1.文件路径(包括驱动器号、目录名、文件名)不区分大小写。   2.被禁可打印ASCII字符是:     \ / : * ? " < > |     \ (backslash,可作为路径分隔符,将一个目录名与路径中的另一个目录名称分开)     / (forward slash)     : (colon - sometimes works, but is actually NTFS Alternate Data Streams,作为驱动器号与目录路径的分隔符)     * (asterisk)     ? (question mark)     " (double quote)     < (less than)     > (greater than)     | (vertical bar or pipe)   3.不可打印字符     如果您的数据来自允许不可打印字符的源,那么还需要检查更多。     0-31 (ASCII control characters,控制字符)   4.保留文件名(包含小写)     AUX, CON, CONIN$, CONOUT$, NUL, PRN     COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9     LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, LPT9     但加上任意的文件扩展名则符合规则,例如,LPT1.txt。     只加一个点号和/或空格可不行,如: CON. 或 CON .      【自测 Win10】          CONIN $,CONOUT $   CONIN(或CONOUT)+空格+$ 是合法文件名。         CONIN$, CONOUT$     也被保留。试图创建则提示是“无效的文件句柄”。         "CONIN$" 和 "CONOUT$" 也是保留字。         与 "CON" 不同,它们允许以读写方式访问控制台输入和屏幕缓冲区。         在 Windows 8 之前,只有基本文件名是保留的。         从 Windows 8 开始,底层的控制台 IPC 被重新设计为使用设备驱动程序,         因此这两个名称现在被通用地作为 DOS 设备处理,与 "NUL" 等相同。         这意味着它们可以用于本地设备路径,例如 "\\.\CONIN$" 和 "\\?\CONOUT$" ,         且还意味着 API 假装这些名称在每个现有目录中都 '存在' 。例如,"C:\Temp\CONOUT$" 引用控制台输出。    【DOS设备名称】         请注意,保留的 DOS 设备名称和文件名以点或空格结尾的规则是在将 DOS 路径转换为本地 NT 路径时由运行时库应用的。         如果路径以 "\\?\" 本地设备前缀开头,则跳过这个规范化步骤,除了用 NT 的 "\??\" 设备前缀替换 "\\?\" 。         这个前缀指示对象管理器在登录会话和全局 DOS 设备目录中搜索一个符号链接,         该符号链接指向一个本地 NT 设备,通常是 "\Device" 目录中的一个设备对象。    【LPT1...9】         使用 Cygwin,您可以轻松创建 lpt1 和 lpt1.txt 等类似设备名。    【不可打印字符】         把 TAB 等字符粘贴进 Cygwin Bash, 可以用它在 Windows 下创建含有特殊字符的文件名。         ls -l 查看显示为 '$'\t 这其实是一个字符,并非两个字符。  5.文件名不能以空格开头或结尾     Windows 自动去除开头和结尾的连续空格。  6.文件名不能以英文点号结尾     - Windows 自动去除结尾的连续点号 ‘.’     - 使用句点作为路径中的目录部分来表示当前目录,例如 ".\\temp.txt"     - 使用两个连续的句点 (..) 作为路径中的目录 组件 来表示父目录,例如 "..\\temp.txt"       因此包括但不止下列文件名均不合法:       .       ..       ...       ....       " ...." 这里要去除双引号,只为表示前面有一个空格       ".... " 这里要去除双引号,只为表示后面有一个空格       ... . ...   7.其他规则     DOS中, 不允许使用 - (hyphen, 连字符)     FAT、exFAT 格式禁止 ^  "CONIN$", "CONOUT$"  8.文件路径长度限制    - 不开启长文件名       Windows 默认不开启长文件名,系统路径的限制长度是 260,文件名的长度最大不超过 255.       在头文件 stdlib.h 中定义           #define MAX_PATH 260       实际的文件名必须少于 260,因为完整路径(如 C:\Program Files\filename.txt)都包含在此字符数值中。       另外末尾要保留一个字节 (GBK) 或两个字节 (UNICODE) 给结束符 (null, 即 \0)。    - 开启长文件名       Windows 开启长文件名时,系统路径的限制长度是 32767,文件名的长度最大不超过 255.       从 Windows 10 version 1607 build 14352 之后,就可以设置启用 enable NTFS long paths 来打破路径最大长度是 260 的限制。       开启的方法是:打开注册表,修改       [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem]       "LongPathsEnabled"=dword:00000001    - 在命令文件时,windows会截断文件名超出长度的部分。     - 在脚本中,文件路径首尾各一个双引号不算在长度内。     - 关于一个汉字占用两个字节,可能与 GBK(GB2312等) 和 UNICODE(UTF-8等) 编码有关。 一个中文字符,GBK: 1; UNICODE: 2 个字节。     - UNC(Universal Naming Convention),即“通用命名约定”。       如果文件路径采用 UNC 规则, 一些前缀不用作路径本身的一部分。如:           \\?\UNC\server\share       其中“server”是计算机的名称,“share”是共享文件夹的名称。这些前缀不用作路径本身的一部分。它们指示路径应以最少的修改传递到系统,       这意味着您不能使用正斜杠来表示路径分隔符,也不能使用句点来表示当前目录,也不能使用双点来表示父目录。       由于不能将“\\?\”前缀与相对路径一起使用,因此相对路径始终限制为总共 MAX_PATH(包括 \0) 个字符。    - 另外,文件名命名规则有些需要继承 DOS 8.3 命名规则,参考         【@iPhilip 实测】 参考文章末尾的讲解。     【我的实测 Windows 11 中文简体】         文件完整路径最多包含 247 个字符,可能 Windows 8.3 API 有关,下面引自 MSDN 原话:         使用 Windows  file I/O API  创建目录时,指定的路径不能太长,以至于无法追加 8.3 文件名(即目录名不能超过 MAX_PATH 减 12)。         合法最长例子:          C:\2441111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111         C:\35111111111111111111111111111111111\2081111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111         C:\35111111111111111111111111111111111\204111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111.txt         C:\31中文11111111111111111111111111111\204111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111.txt         C:\31中文11111111111111111111111111111\20611111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111.txt         注:上面文件完整路径是 3+33+1+206 个字符+4=247, 说明一个中文文字只占一个字符。             把最长命名的文件移动到比当前目录长度更长的目录路径中,不会报错,不会修改文件名。             这时再读取这个文件时会出错,但可使用短文件名路径访问,如:             type "C:\244111~1\111111~1"

 Linux/Unix:

  1.被禁可打印ASCII字符是     / (forward slash)     注: Linux/Unix文件名具有控制字符是合法的,对用户来说,处理这些文件可能是一场噩梦。。          最好文件名中不要包含 : ? @ # $&()|; ‘’“”等字符,另外 空格符,制表符和退格符也不建议使用。          避免使用 + - 和. 作为文件名的第一个字符(Linux下以.开头的文件是隐藏文件)。  2.不可打印字符     \0 (NULL byte)  3.文件路径长度限制     limits.h 头文件里面有针对 NAME 和 PATH 的最大长度限制:         #define NAME_MAX         255    /* # chars in a file name */         #define PATH_MAX        4096    /* # chars in a path name including nul */     完整路径: 4096 字节; 文件名: 255 字节。

 MacOS HFS+:

  1.被禁可打印ASCII字符是:     : (colon 英文冒号被禁, 中文冒号:可以)  2.其他规则     . (dot 英文点号不能放在文件名开头, 中文句号‘。’可以)  3.文件路径长度限制     syslimits.h 头文件里面有针对 NAME 和 PATH 的最大长度限制:         #define NAME_MAX         255    /* # max bytes in a file name */         #define PATH_MAX        1024    /* # max bytes in pathname */     完整路径: 1024 字节; 文件名: 255 字节。

          :: ---------------------------------------------------------------------------------------------------------------------

https://www.autohotkey.com/boards/viewtopic.php?t=86131 https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-fscc/18e63b13-ba43-4f5f-a5b7-11e871b71f14

【@iPhilip 实测】

I did some tests with the script below and I can make the following observations: 我用下面的脚本做了一些测试,我可以做出以下观察:

The maximum number of characters in a path is 259 (MAX_PATH - 1).路径中的最大字符数为 259 (MAX_PATH - 1)。

The maximum number of characters in a file name is 255, e.g. drive letter + :\ + 255 file name characters.文件名中的最大字符数为 255,例如驱动器号 + :\ + 255 个文件名字符。

The maximum number of characters in a folder name is 244, e.g. drive letter + :\ + 244 folder name characters.文件夹名称中的最大字符数为 244,例如驱动器号 + :\ + 244 个文件夹名称字符。

When combined with a backlash and a file name the maximum number of characters in a folder name is 243, e.g. drive letter + :\ + 243 folder name characters + \ + 12 file name characters.  The 12 characters represent the number of characters in an 8.3 file name. This is consistent with the following statement from the Maximum Path Length Limitation page: 当与反斜杠和文件名结合使用时,文件夹名称中的最大字符数为 243,例如驱动器号 + :\ + 243 个文件夹名称字符 + \ + 12 个文件名字符。 这 12 个字符表示 8.3 文件名中的字符数。 8 个基本文件名字符 + . + 最多 3 个扩展名字符。

The base filename MUST be 1-8 characters in length and MUST NOT contain a "." period character. 基本文件名的长度必须为 1-8 个字符,并且不得包含“.”句点字符。

The filename extension, if present, MUST be 1-3 characters in length and MUST NOT contain a "." period character. 文件扩展名(如果存在)长度必须为 1-3 个字符,并且不得包含“.”句点字符。

这与“最大路径长度限制”页中的以下语句一致:

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). 使用 API 创建目录时,指定的路径不能太长,以至于无法追加 8.3 文件名(即目录名不能超过 MAX_PATH 减 12)。

Here is the script:  这是脚本: #NoEnv ; Admin priviledges are required to create files and/or folders in the root directory full_command_line := DllCall("GetCommandLine", "str") if not (A_IsAdmin or RegExMatch(full_command_line, " /restart(?!\S)")) {    try    {       if A_IsCompiled          Run *RunAs "%A_ScriptFullPath%" /restart       else          Run *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%"    }    ExitApp } MAX_PATH := 260 ; Test of longest path in the script directory Loop {    MaxChars := MAX_PATH - A_Index    LongPath := A_ScriptDir "\"    NoChars := StrLen(LongPath)    Loop, % MaxChars - NoChars - 4       LongPath .= "x"    LongPath .= ".txt"    FileAppend, , % LongPath    if FileExist(LongPath)       break } MsgBox % "The file path has " StrLen(LongPath) " characters.`nThe file name has " StrLen(LongPath) - NoChars " characters.`nThe first 25 characters are: " SubStr(LongPath, 1, 25) "`nThe last 25 characters are: " SubStr(LongPath, -24) "`n`nClick OK to delete it." FileDelete, % LongPath ; Test of the longest filename in the C:\ folder Loop {    MaxChars := MAX_PATH - A_Index    LongPath := "C:\"    NoChars := StrLen(LongPath)    Loop, % MaxChars - NoChars - 4       LongPath .= "x"    LongPath .= ".txt"    FileAppend, , % LongPath    if FileExist(LongPath)       break } MsgBox % "The file path has " StrLen(LongPath) " characters.`nThe file name has " StrLen(LongPath) - NoChars " characters.`nThe first 25 characters are: " SubStr(LongPath, 1, 25) "`nThe last 25 characters are: " SubStr(LongPath, -24) "`n`nClick OK to delete it." FileDelete, % LongPath ; Test of the longest folder in the C:\ folder Loop {    MaxChars := MAX_PATH - A_Index    LongPath := "C:\"    NoChars := StrLen(LongPath)    Loop, % MaxChars - NoChars       LongPath .= "x"    FileCreateDir, % LongPath    if FileExist(LongPath)       break } MsgBox % "The folder path has " StrLen(LongPath) " characters.`nThe folder name has " StrLen(LongPath) - NoChars " characters.`nThe first 25 characters are: " SubStr(LongPath, 1, 25) "`nThe last 25 characters are: " SubStr(LongPath, -24) "`n`nClick OK to delete it." FileRemoveDir, % LongPath ; Test of the longest folder + 8.3 file name in the C:\ folder Loop {    MaxChars := MAX_PATH - A_Index    LongPath := "C:\"    NoChars := StrLen(LongPath)    Loop, % MaxChars - NoChars - 13  ; StrLen("\") + 8 + 1 + 3 (8.3 file) = 13       LongPath .= "x"    LongPath .= "\"    FileCreateDir, % LongPath    Folder := LongPath    LongPath .= "12345678.123"    FileAppend, , % LongPath    if FileExist(LongPath)       break } MsgBox % "The folder path has " StrLen(LongPath) " characters.`nThe folder name has " StrLen(Folder) - NoChars - 1 " characters.`nThe first 25 characters are: " SubStr(LongPath, 1, 25) "`nThe last 25 characters are: " SubStr(LongPath, -24) "`n`nClick OK to delete it." FileDelete, % LongPath FileRemoveDir, % Folder ExitApp

Thus, the statement in the Long Paths section of the documentation is partially correct in that a single file name,  but not a folder name, has a maximum length of 255 characters.  I modified my original post to reflect the above observations. 因此,文档的“长路径”部分中的语句部分正确,因为单个文件名(而不是文件夹名称)的最大长度为 255 个字符。 我修改了我的原始帖子以反映上述观察结果。      :: ---------------------------------------------------------------------------------------------------------------------

 

              



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有