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

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

问题描述

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

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

  • 尝试在具有深层路径的开源Java项目上工作
  • 在源代码管理中存储Deep Fitnesse Wiki树
  • 尝试使用Bazaar导入我的源代码管理树时发生错误

为什么存在此限制?

为什么还没有将其删除?

Why hasn't it been removed yet?

您如何应对路径限制? 而且,不,切换到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 ;)

推荐答案

引用本文

最大路径长度限制

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

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天全站免登陆