[英]Fully qualified path Vs. Canonical Path
There is a canonical path concept in Java. Java中有一个规范路径概念。
And there is a fully-qualified path in WinApi. WinApi中有一条完全合格的路径。
I know well what canonical path is, but I don't understand fully-qualified path's concepts . 我很清楚规范路径是什么,但我不理解完全合格路径的概念 。
For a file or directory, does fully-qulified path exist only one thing? 对于文件或目录,完全排序的路径只存在一件事吗? -like canonical path. 类似的规范路径。
Are both of them totally same concepts? 它们都是完全相同的概念吗?
Edit : 编辑 :
One more thing, Is a symbloc link or a hard link belong to Fully qualified path? 还有一件事,符号链接或硬链接是否属于完全限定路径?
Edit 编辑
I asked someone who maintains Naming Files, Paths, and Namespaces page to let me know this. 我问维护命名文件,路径和命名空间页面的人让我知道这一点。
And he replied me. 他回答说。
Is this also Fully-qualified path? 这也是完全合格的路径吗?
C:\\directory\\..\\directory\\file.txt C:\\目录\\ .. \\目录\\ file.txt的
Technically that is a relative path because it contains the double dot (..) and some APIs do not process those correctly (the docs will clearly state that it needs a fully qualified path). 从技术上讲,这是一个相对路径,因为它包含双点(..),而某些API不能正确处理它们(文档将明确指出它需要一个完全限定的路径)。
The two are mutually exclusive. 这两者是相互排斥的。
What he means is, in my guessing, if we put a param like this "C:\\directory\\..\\directory\\file.txt" to the function required fully-qualified path, the function never reinterpret the path and then fails. 他的意思是,在我的猜测中,如果我们将一个像这样的“C:\\ directory \\ .. \\ directory \\ file.txt”的参数放到函数所需的完全限定路径中,该函数永远不会重新解释路径然后失败。
If so, fully-qualified path is totally same with an canonical path. 如果是这样,完全限定的路径与规范路径完全相同。 Isn't it. 不是吗
Every location on a file system has a multitude of paths that could be used to refer to it, including numerous fully-qualified paths : 文件系统上的每个位置都有许多可用于引用它的路径 ,包括许多完全限定的路径 :
Conceptually speaking, one of those fully-qualified paths is the simplest, most straightforward way of specifying that resource - that's your canonical path . 从概念上讲,其中一条完全合格的路径是指定该资源的最简单,最直接的方式 - 这是您的规范路径 。
For a file or directory, does fully-qulified path exist only one thing? 对于文件或目录,完全排序的路径只存在一件事吗? -like canonical path. 类似的规范路径。
No, a fully-qualified path is any path which is not a relative path (not relative to the current directory of the implied or specified context). 不,完全限定路径是任何不是相对路径的路径(不相对于隐含或指定上下文的当前目录)。 Multiple, but distinct, fully-qualified paths could refer to the same location on the filesystem. 多个但不同的完全限定路径可以引用文件系统上的相同位置。 Reread: 重读:
What's the difference between getPath(), getAbsolutePath(), and getCanonicalPath() in Java? Java中的getPath(),getAbsolutePath()和getCanonicalPath()有什么区别?
but substitute "fully-qualified" everywhere it says "absolute". 但在所谓的“绝对”的地方替换“完全合格”。
To be clear, some people will also use the term "relative path" to also refer to a path with a "relative reference" (double dots ..
) within it. 为了清楚起见,有些人还会使用术语“相对路径”来引用其中包含“相对引用”(双点..
)的路径。 For example, some might might called C:\\Program Files\\Microsoft\\\\..\\temp.txt
a "relative path" because of the double dots, but I would call it an fully-qualified path with a relative reference. 例如,有些人可能会因为双点而将C:\\Program Files\\Microsoft\\\\..\\temp.txt
称为“相对路径”,但我将其称为具有相对引用的完全限定路径。 Hopefully, it will be clear from the conversation what they mean when they say "relative path" (a path that is relative to a context or a path with a relative reference in it). 希望从对话中可以清楚地看出,当他们说“相对路径”(相对于上下文或具有相对引用的路径的路径)时,它们的含义是什么。
Are both of them totally same concepts? 它们都是完全相同的概念吗?
No, as indicated in the other SO question, there are lots ways to specify a fully-qualified path (absolute path) to a location, but only one of those fully-qualified paths is considered to be the canonical path to that location. 不,如另一个SO问题所示,有很多方法可以指定一个位置的完全限定路径(绝对路径),但只有一个完全限定路径被认为是该位置的规范路径。
One more thing, Is a UNC path belong to fully-qualified path too? 还有一件事,UNC路径是否也属于完全合格的路径?
Yes, UNC paths are not relative paths; 是的,UNC路径不是相对路径; they are fully-qualified paths. 他们是完全合格的道路。 - http://msdn.microsoft.com/en-us/library/aa365247(v=VS.85).aspx#fully_qualified_vs._relative_paths - http://msdn.microsoft.com/en-us/library/aa365247(v=VS.85).aspx#fully_qualified_vs._relative_paths
Is a symbolic link or a hard link belong to Fully qualified path? 符号链接或硬链接是否属于完全限定路径?
Its an independent concept. 它是一个独立的概念。 A path (regardless of whether it is relative or full-qualified) leads to a location in the filesystem. 路径(无论是相对路径还是完全合格路径)都会导致文件系统中的某个位置。 The entity at that location could be one of many things: a normal file, a directory, a symbolic link, a hard link, a device, a named pipe, etc. A symbolic links or a hard link has meta-data that leads to the data you were actually looking for at that location. 该位置的实体可以是许多内容之一:普通文件,目录,符号链接,硬链接,设备,命名管道等。符号链接或硬链接具有导致您在该位置实际查找的数据。
You can think of paths and links in the terms of directions to someone's house: 您可以根据指向某人家的方向来考虑路径和链接:
/
". 在我们奇怪的小镇Unixville,每个人都同意并理解,“完全合格的方向”总是从市政厅开始,奇怪的是,每个人都称之为“ /
”。 C:\\
, D:\\
, E:\\
, etc. (Windowsville)下一个城镇有多个市政厅(每个城镇一个),名为C:\\
, D:\\
, E:\\
等。 10 Elm Str
and 20 Main Str
. 邮局错误地给了它两个地址: 10 Elm Str
和20 Main Str
。 No matter which address you go to, you end up at the same house. 无论你去哪个地址,你最终都会在同一所房子里。 Addendum 附录
Edit 编辑
I asked someone who maintains Naming Files, Paths, and Namespaces page to let me know this. 我问维护命名文件,路径和命名空间页面的人让我知道这一点。 And he replied me. 他回答说。
Is this also Fully-qualified path? 这也是完全合格的路径吗? C:\\directory..\\directory\\file.txt C:\\目录.. \\目录\\ file.txt的
I wonder what terms the maintainer of that page would use to differentiate between ..\\file.txt
and C:\\directory\\..\\directory\\file.txt
since he calls them both relative path. 我想知道该页面的维护者用什么术语来区分..\\file.txt
和C:\\directory\\..\\directory\\file.txt
因为他将它们称为相对路径。 I agree that double dots are a relative reference, but I wouldn't tag the whole path as relative because it has double dots in the middle of it. 我同意双点是相对参考,但我不会将整个路径标记为相对路径,因为它在中间有双点。 In his terminology, there doesn't seem to be a difference between fully-qualified and canonical. 在他的术语中,完全合格和规范之间似乎没有区别。 (Therein, I suppose, lies the source of your question). (其中,我认为,这是你问题的根源)。
I come from a Unix and Java background, so perhaps that makes the difference. 我来自Unix和Java背景,所以也许这会带来不同。 As I learned it: 据我所知:
relative/partially-qualified - location cannot be determined without the associated context providing information, eg the current working directory, the current drive, the drive's current directory, the shell PATH setting, the Java CLASSPATH setting, or the referencing URL. relative / partial-qualified - 如果没有关联的上下文提供信息,则无法确定位置,例如当前工作目录,当前驱动器,驱动器的当前目录,shell PATH设置,Java CLASSPATH设置或引用URL。
absolute/fully-qualified - location is independent of the the associated context, ie the location is the same regardless of the current working directory, the current drive, the drive's current directory, the shell PATH setting, the Java CLASSPATH setting, or the referencing URL. 绝对/完全限定 - 位置独立于关联的上下文,即无论当前工作目录,当前驱动器,驱动器的当前目录,shell PATH设置,Java CLASSPATH设置或引用,位置都是相同的URL。
canonical - the simplest fully-qualified, ie no double-dots 规范 - 最简单的完全合格,即没有双点
So 所以
That section of the MSDN page isn't clear on C:\\directory\\..\\directory\\file.txt
: If C:\\directory\\..\\directory\\file.txt
is considered relative and won't work with Windows API that say they need a fully-qualified (but not necessarily canonical?) path, I'd suggest that page needs to make that clearer. MSDN页面的该部分在C:\\directory\\..\\directory\\file.txt
不明确:如果C:\\directory\\..\\directory\\file.txt
被认为是相对的,则无法与Windows API一起使用那说他们需要一个完全合格的(但不一定是规范的)路径,我建议页面需要更清楚。
Fully-qualfied vs Relative 完全合格与相对
A file name is relative to the current directory if it does not begin with one of the following: 如果它不与下面的一个开头的文件名是相对于当前目录:
... * A disk designator with a backslash, for example "C:\\" or "d:\\". ... * 带反斜杠的磁盘指示符,例如“C:\\”或“d:\\”。 ... ...
Since C:\\directory\\..\\directory\\file.txt
starts with a disk designator with a blackslash, this path is fully-qualified, not relative. 由于C:\\directory\\..\\directory\\file.txt
以带有黑名单的磁盘指示符开头,因此该路径是完全限定的,而不是相对的。
A path is also said to be relative if it contains "double-dots" ; 如果路径包含“双点” , 则该路径也称为相对路径; that is, two periods together in one component of the path. 也就是说,路径的一个组成部分中有两个周期。 This special specifier is used to denote the directory above the current directory , otherwise known as the "parent directory". 此特殊说明符用于表示当前目录上方的目录 ,也称为“父目录”。 Examples of this format are as follows: 此格式的示例如下:
- "..\\tmp.txt" specifies a file named tmp.txt located in the parent of the current directory. “.. \\ tmp.txt”指定位于当前目录的父级中的名为tmp.txt的文件。
- "....\\tmp.txt" specifies a file that is two directories above the current directory. “.... \\ tmp.txt”指定一个文件,它是当前目录上方的两个目录。
- "..\\tempdir\\tmp.txt" specifies a file named tmp.txt located in a directory named tempdir that is a peer directory to the current directory. “.. \\ tempdir \\ tmp.txt”指定名为tmp.txt的文件,该文件位于名为tempdir的目录中,该目录是当前目录的对等目录。
I interpreted the phrase contains double dots to mean leading double dots. 我解释这个短语包含双点意味着领先的双点。 The examples show only leading double dots. 示例仅显示前导双点。 The terminology "current directory" usually means process's current working directory or the drive's current directory, which has bearing only when talking about leading double dots. 术语“当前目录”通常表示进程的当前工作目录或驱动器的当前目录,仅在讨论前导双点时才有意义。 I can, however, see how the section could be interpreted the other way. 但是,我可以看到如何以另一种方式解释该部分。
Regardless , everyone grows up different and context is king, so I guess everyone will need to be careful of the nuances when reading docs or discussing with engineers of different backgrounds on what they mean by "fully-qualified" vs "relative" 无论如何 ,每个人的成长都不同,背景也是王道,所以我想每个人在阅读文档或与不同背景的工程师讨论“完全合格”与“相对”的含义时,需要注意细微差别。
No. IMHO, fully-qualified path only lets you find the resource in unambiguous manner (independent on the current working directory, PATH environ, etc) but two different paths may identify the same resource. 恕我直言,完全限定路径只允许您以明确的方式查找资源(独立于当前工作目录,PATH环境等),但两条不同的路径可以识别相同的资源。
I am unaware of a windows way of knowing if two paths point to the same file. 我不知道windows方式知道两个路径是否指向同一个文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.