在 Windows 上,应用程序输出可接受的最大文件名长度是多少?(更新和澄清)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8674796/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 18:46:06  来源:igfitidea点击:

On Windows, what is the maximum file name length considered acceptable for an app to output? (Updated and clarified)

windowsfilenamesmaxlength

提问by Alex

Many Windows applications (e.g., almost all .NET apps) cannot open paths more than 260 characters in length. I am batch renaming a list of podcast files. I want to name each file after the title of the episode, but the titles are up to 100 characters long. This means that if a user saves the file in a deep directory with a very long path, they may hit the limit and be unable to open the file in those other applications.

许多 Windows 应用程序(例如,几乎所有 .NET 应用程序)都无法打开长度超过 260 个字符的路径。我正在批量重命名播客文件列表。我想在剧集的标题后命名每个文件,但标题长达 100 个字符。这意味着如果用户将文件保存在路径很长的深层目录中,他们可能会达到限制并且无法在其他应用程序中打开文件。

Is it acceptable for my program to put out file names this long, and leave it to the user to deal with very long paths when it comes up? iTunes crops at 40 chars, but that seems very conservative.

我的程序是否可以将文件名输出这么长,然后让用户处理很长的路径?iTunes 裁剪为 40 个字符,但这似乎非常保守。

Thanks to Ben Voigt for clarifying that this only applies to certain apps.

感谢 Ben Voigt 澄清这仅适用于某些应用程序。

回答by Ben Voigt

Windows does NOT have a limit of 255 characters for file paths.

Windows 对文件路径没有 255 个字符的限制。

CreateFileAhas a limit of 260 characters. CreateFileWsupports names up to about 32760 characters (64kB).

CreateFileA限制为 260 个字符。 CreateFileW支持最多约 32760 个字符 (64kB) 的名称。

Some filesystems impose additional limits on the maximum directory nesting level, or the maximum length of each part.

一些文件系统对最大目录嵌套级别或每个部分的最大长度施加了额外的限制。

You're probably thinking of certain popular Windows programs that have a 255 character limit, but accommodating those with a warning or user-configurable setting is probably more appropriate than adding your own hard limit.

您可能正在考虑某些具有 255 个字符限制的流行 Windows 程序,但为那些带有警告或用户可配置设置的程序提供支持可能比添加您自己的硬限制更合适

回答by Tixz

Well I remember having an USB that didn't support more than 32 characters in the filename (can't remember which FS it had). I also just found this link on Google: http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx

好吧,我记得有一个 USB 文件名不支持超过 32 个字符(不记得它有哪个 FS)。我也刚刚在谷歌上找到了这个链接:http: //msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx

Character count limitations can also be different and can vary depending on the file system and path name prefix format used. This is further complicated by support for backward compatibility mechanisms. For example, the older MS-DOS FAT file system supports a maximum of 8 characters for the base file name and 3 characters for the extension, for a total of 12 characters including the dot separator. This is commonly known as an 8.3 file name. The Windows FAT and NTFS file systems are not limited to 8.3 file names, because they have long file name support, but they still support the 8.3 version of long file names.

字符数限制也可能不同,并且可能因所使用的文件系统和路径名前缀格式而异。由于支持向后兼容机制,这进一步复杂化。例如,较旧的 MS-DOS FAT 文件系统支持最多 8 个字符的基本文件名和 3 个字符的扩展名,总共 12 个字符,包括点分隔符。这通常称为 8.3 文件名。Windows FAT 和 NTFS 文件系统不限于 8.3 文件名,因为它们有长文件名支持,但它们仍然支持 8.3 版本的长文件名。