windows - 为什么 Windows 存在 260 个字符的路径长度限制?

标签 windows path limit

我在不合时宜的时候遇到过几次这个问题:

  • 尝试从事具有深度路径的开源 Java 项目
  • 在源代码管理中存储深度 Fitnesse wiki 树
  • 尝试使用 Bazaar 导入我的源代码管理树时出错

为什么存在这个限制?

为什么还没有删除?

您如何应对路径限制? 不,切换到 Linux 或 Mac OS X 不是这个问题的有效答案;)

最佳答案

引用本文https://learn.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file#maximum-path-length-limitation

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/

相关文章:

Windows 代码签名证书信任期

jquery - 如何获取 jQuery 的基本路径?

Python项目目录结构/pytest麻烦

mysql - MySQL 数据库表中的最大记录数

windows - 在 Windows 上的 R 中读取带有 SUB (1a) (Control-Z) 字符的文本文件

windows - 如何使用API​​读取声卡DMA缓冲区?

php - 在 PHP 中连接到数据库

通过 CMD 的 Java 命令在 C#.NET 中不起作用

matlab - 在 matlab 中使用 rand 生成限制之间的数字

mysql - 获取数据库中的最后 5 行并按 ASC 排序