xiaowuhello
it你好论坛技巧推荐"\\?\path.ext"是什么?

注册表中经常出现类似\\?\c:\path\filename.ext的文件,前面的\\?\让我很是迷惑。这个东西到底是什么?有什么作用?能够防止更改?防止删除?临时文件?

今天无意中在MSDN的CFile的链接里,看到如下解释:

Maximum Path LengthIn the Windows API, the maximum length for a path is MAX_PATH, which is defined as 260 characters. A path is structured in the following order: drive letter, colon, backslash,

components separated by backslashes, and a null-terminating character, for example, the maximum path on the D drive is D:\<256 chars>NUL.

在WINDOWS API函数中,路径的最大值用MAX_PATH来限定,通常是260个字符,结构如下:“盘符”,“:”,“\”,路径,以及一个由“\0”结尾的字符串组成。

例如:在D盘的最长的一个路径可以是这样的形式:

D:\123456789\123456789\123456789\123456789\123456789\123456789\123456789\123456789\123456789\123456789\123456789\123456789\123456789\123456789\123456789\123456789\123456789\123456789\123456789\123456789\123456789\123456789\123456789\123456789\123456789\12.345NUL

The Unicode versions of several functions permit a maximum path length of approximately 32,000 characters composed of components up to 255 characters in length. To specify that kind of path, use the "\\?\" prefix.

而UNICODE版本下的某些函数,允许的最大路径长度可以达到32000个字符,只要在原有路径前加上前缀“\\?\”就可以了。

Note The maximum path of 32,000 characters is approximate, because the "\\?\" prefix can be expanded to a longer string, and the expansion applies to the total length.

For example, "\\?\D:\ *本站禁止HTML标签噢* ". To specify such a UNC path, use the "\\?\UNC\" prefix. For example, "\\?\UNC\ *本站禁止HTML标签噢* \ *本站禁止HTML标签噢* ". These prefixes are not used as part of the path itself. They indicate that the path should be passed to the system with minimal modification. An implication of this is that you cannot use forward slashes to represent path separators, or a period to represent the current directory. You cannot use the "\\?\" prefix with a relative path. Relative paths are limited to MAX_PATH characters.

When using the API to create a directory, the specified path cannot be so long that you could not append an 8.3 file name.

The shell and the file system may have different requirements. It is possible to create a path with the API that the shell UI cannot handle.

翻译比自己看要累,就翻两段了:(

原来这个前缀是为了突破文件路径最长为260个字符的限制,从而让路径的长度可以达到32000字符。