为什么 Windows 中存在 260 个字符的路径长度限制? [英] Why does the 260 character path length limit exist in Windows?

查看:32
本文介绍了为什么 Windows 中存在 260 个字符的路径长度限制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have come up against this problem a few times at inopportune moments:

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

为什么会存在这个限制?

Why does this limit exist?

为什么还没有被删除?

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

How do you cope with the path limit? And no, switching to Linux or Mac OS X is not a valid answer to this question ;)

推荐答案

引用这篇文章 https://docs.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file#maximum-path-length-limitation

最大路径长度限制

在 Windows API 中(以下段落中讨论的一些例外情况除外),路径的最大长度为 MAX_PATH,定义为 260 个字符.本地路径按以下顺序构造:驱动器号、冒号、反斜杠、由反斜杠分隔的名称组件和终止空字符.例如,驱动器 D 上的最大路径是 "D:some 256-character path string" 其中 "" 表示当前系统代码页的不可见终止空字符.(这里使用字符 < > 是为了视觉清晰,不能是有效路径字符串的一部分.)

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带符号)最大驱动器(和当前目录).

Now we see that it is 1+2+256+1 or [drive][:][path][null] = 260. One could assume that 256 is a reasonable fixed string length from the DOS days. And going back to the DOS APIs we realize that the system tracked the current path per drive, and we have 26 (32 with symbols) maximum drives (and current directories).

INT 0x21 AH=0x47 表示此函数返回没有驱动器号和初始反斜杠的路径描述."所以我们看到系统将 CWD 存储为一对(驱动器,路径),您通过指定驱动器(1=A,2=B,...)来请求路径,如果您指定 0,则它假定路径为INT 0x21 AH=0x15 AL=0x19 返回的驱动器.所以现在我们知道为什么它是 260 而不是 256,因为那 4 个字节没有存储在路径字符串中.

The INT 0x21 AH=0x47 says "This function returns the path description without the drive letter and the initial backslash." So we see that the system stores the CWD as a pair (drive, path) and you ask for the path by specifying the drive (1=A, 2=B, …), if you specify a 0 then it assumes the path for the drive returned by INT 0x21 AH=0x15 AL=0x19. So now we know why it is 260 and not 256, because those 4 bytes are not stored in the path string.

为什么是 256 字节的路径字符串,因为 640K 的 RAM 就足够了.

Why a 256 byte path string, because 640K is enough RAM.

这篇关于为什么 Windows 中存在 260 个字符的路径长度限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆