windows \\?\ 在文件路径前面是什么意思

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21194530/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 11:16:45  来源:igfitidea点击:

What does \\?\ mean when prepended to a file path

windowsfilepath

提问by bjjer

I found a reference to a file in a log that had the following format:

我在具有以下格式的日志中找到了对文件的引用:

\?\C:\Path\path\file.log

I cannot find a reference to what the sequence of \?\ means. I believe the part between the backslashes refers to a hostname.

我找不到对 \?\ 序列含义的引用。我相信反斜杠之间的部分是指主机名。

For instance, on my Windows computer, the following works just fine:

例如,在我的 Windows 计算机上,以下工作正常:

dir \?\C:\

and also, just fine with same result:

而且,同样的结果就好了:

dir \.\C:\

Questions:

问题:

  1. Is there a reference to what the question mark means in this particular path format?
  2. What might generate a file path in such a format?
  1. 问号在此特定路径格式中的含义是否有参考?
  2. 什么可能生成这种格式的文件路径?

回答by Ferenc Deak

A long read, but worth reading if you are in this domain: http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247%28v=vs.85%29.aspx

长篇阅读,但如果您在此域中,则值得一读:http: //msdn.microsoft.com/en-us/library/windows/desktop/aa365247%28v=vs.85%29.aspx

Extract:

提炼:

The Windows API has many functions that also have Unicode versions to permit an extended-length path for a maximum total path length of 32,767 characters. This type of path is composed of components separated by backslashes, each up to the value returned in the lpMaximumComponentLengthparameter of the GetVolumeInformationfunction (this value is commonly 255 characters). To specify an extended-length path, use the "\\?\"prefix. For example, "\\?\D:\very long path".

Windows API 有许多函数,这些函数也有 Unicode 版本,以允许最大总路径长度为 32,767 个字符的扩展长度路径。这种类型的路径由反斜杠分隔的组件组成,每个组件最多为 函数lpMaximumComponentLength参数中返回的值 GetVolumeInformation(该值通常为 255 个字符)。要指定扩展长度的路径,请使用"\\?\"前缀。例如,"\\?\D:\very long path"

and:

和:

The "\\?\"prefix can also be used with paths constructed according to the universal naming convention (UNC). To specify such a path using UNC, use the "\\?\UNC\"prefix. For example, "\\?\UNC\server\share", where "server"is the name of the computer and "share"is the name of the shared folder. 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, which means that you cannot use forward slashes to represent path separators, or a period to represent the current directory, or double dots to represent the parent directory. Because you cannot use the "\\?\"prefix with a relative path, relative paths are always limited to a total of MAX_PATHcharacters.

"\\?\"前缀还可以与根据通用命名约定 (UNC) 构造的路径一起使用。要使用 UNC 指定这样的路径,请使用"\\?\UNC\"前缀。例如,"\\?\UNC\server\share"其中"server"是计算机"share"的名称, 是共享文件夹的名称。这些前缀不用作路径本身的一部分。它们表示路径应该以最少的修改传递给系统,这意味着您不能使用正斜杠表示路径分隔符,或使用句点表示当前目录,或使用双点表示父目录。由于不能将"\\?\"前缀与相对路径一起使用,因此相对路径始终限制为总共MAX_PATH字符数。

回答by IInspectable

The Windows API parses input strings for file I/O. Among other things, it translates /to \as part of converting the name to an NT-style name, or interpreting the .and ..pseudo directories. With few exceptions, the Windows API also limits path names to 260 characters.

Windows API 解析文件 I/O 的输入字符串。除其他事项外,将其转换/\作为名称转换为NT风格的名称,或解释的部分...伪目录。除了少数例外,Windows API 还将路径名限制为 260 个字符。

The documentedpurpose of the \\?\prefix is:

前缀的记录目的\\?\是:

For file I/O, the "\\?\" prefix to a path string tells the Windows APIs to disable all string parsing and to send the string that follows it straight to the file system.

对于文件 I/O,路径字符串的“\\?\”前缀告诉 Windows API 禁用所有字符串解析并将其后的字符串直接发送到文件系统。

This allows the use of .or ..in path names, as well as relaxing the 260 character path name limit, if the underlying file system supports long paths and file names.

如果底层文件系统支持长路径和文件名,这允许在路径名中使用...,以及放宽 260 个字符的路径名限制。