我在不合时宜的时候遇到过几次这个问题:
- 尝试从事具有深度路径的开源 Java 项目
- 在源代码管理中存储深度 Fitnesse wiki 树
- 尝试使用 Bazaar 导入我的源代码管理树时出错
为什么存在这个限制?
为什么还没有删除?
您如何应对路径限制? 不,切换到 Linux 或 Mac OS X 不是这个问题的有效答案;)
最佳答案
Maximum Path Length Limitation
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. A local path is structured in the following order: drive letter, colon, backslash, name components separated by backslashes, and a terminating null character. For example, the maximum path on drive D is "D:\some 256-character path string<NUL>" where "<NUL>" represents the invisible terminating null character for the current system codepage. (The characters < > are used here for visual clarity and cannot be part of a valid path string.)
现在我们看到它是 1+2+256+1 或 [drive][:\][path][null] = 260。可以假设 256 是 DOS 时代的一个合理的固定字符串长度。回到 DOS API,我们意识到系统跟踪每个驱动器的当前路径,我们有 26 (32 with symbols) maximum drives (和当前目录)。
INT 0x21 AH=0x47 表示“此函数返回不带驱动器号和初始反斜杠的路径描述。”所以我们看到系统将 CWD 存储为一对(驱动器、路径)并且您通过指定驱动器(1=A、2=B、...)来请求路径,如果您指定 0,则它假定路径为INT 0x21 AH=0x15 AL=0x19 返回的驱动器。所以现在我们知道为什么它是 260 而不是 256,因为这 4 个字节没有存储在路径字符串中。
为什么是 256 字节的路径字符串,因为 640K 足够 RAM。
关于windows - 为什么 Windows 存在 260 个字符的路径长度限制?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1880321/