Conceptually, there is a rather big difference between canonical path and
absolute path.
This is what is usually understood by the word 'canonical':
- Values of Objects have representations, usually String representations
(from now on, I only will refer to them as String representations, since
they deal with user-input and user readable output). Each representation
must be *valid* for that particular object. However, one Object can have
multiple representations. For example, take an Integer that contains the
value 5. Valid representations are "5", "00005", "+5", "5.0", "0.5e+01",
etc. (invalid representations are "Hello", "QQlq"..hehehe). But there is
exactly 1 *canonical* representation of this Integer! The canonical
representation is one from the set of valid representations. Which one...?
That is usually agreed upon by commitees, drafts (RFCs), mathematical
notations, etc. In this case, the Integer's canonical representation would
be "5".
File-paths have something similar:
1- A file can have many relative paths.
2- Canonical paths are absolute paths.
3- An absolute path is not necessarly a canonical path! This holds true
especially under Unix, which support symbolic links. Under Windows, an
absolute path is usually a canonical path.
Example:
- A file with canonical path "/usr/somedir/subdir/file.txt"
- The 'current directory' is "/usr/somedir/subdir2"
- Subdir2 contains a symbolic link to this "file.txt" file, called "symlink"
Then these are valid relative paths to file.txt
"../subdir/file.txt", "../../somedir/subdir/file.txt",
"././././././file.txt"
These are valid absolute paths to file.txt:
"/usr/somedir/subdir/file.txt", "/usr/somedir/subdir2/symlink"
But only one out of all the valid paths is the canonical. It probably is
this one:
"/usr/somedir/subdir/file.txt"
How a canonical path is exactly defined for a File, you may have to check
from RFCs for that.
-- Anton Spaans.