What is a relative path ?
About
A relative path is a path that does not start with a root (prefix)
It is relative to another path that is unknown. You need to transform it as absolute|absolute path before accessing any file.
Relative path vs Absolute Path
Below is an example of a relative because it does not start with a root (prefix)
joe/foo
Below is an example of an absolute path because it does start with a root (the Linux root)
/joe/foo
Advantages vs Disadvantages
Portable
Relative file paths are much more portable because they don't depend on the whole path.
Therefore your files can be installed in two different directories. Via a configuration, your application can calculate the two differents absolute path
Not an file identifier
A relative path is not a file identifier while an absolute path is.
Therefore, it does not identify uniquely a file and needs to be transformed as absolute path.
How to get an absolute path ?
To get an absolute path from a relative path, you need to concatenate:
- to the relative path
By default, the absolute path applied is the working directory (known also as current or default directory).