A path to an entity (in this case, a file, folder, or web page) describes the entity’s unique location within a hierarchical directory or website structure.
Paths can be of two types. They can either be absolute or relative.
The absolute path (also known as the full path) of an entity contains the complete information (from the root to the ending) needed to locate it. The absolute path is not affected by the user’s current working directory, and it always includes the root directory as a starting point.
Let’s use the figure above to illustrate examples of absolute paths. The absolute path to the Macaroni file is: C:\Recipes\Pasta\Macaroni
.
While the absolute path to the CheeseCake file is: C:\Recipes\Cakes\CheeseCake
.
Note: Here,
C:\
is the root directory, andC:\Recipes
is the current working directory.
Absolute paths are easier to understand, but they can be inconvenient to work with as each step from the root to the entity needs to be included.
The relative path of an entity contains the information needed to locate that entity relative to the user’s current working directory. The relative path disregards the information needed to locate the current working directory from the root directory and only focuses on the route from the working directory to the entity.
To understand this better, let’s study the relative paths to the Macaroni file and the CheeseCake file we discussed earlier. Since the relative path uses the current working directory as a vantage point, the Macaroni file’s relative path is Pasta\Macaroni
and the relative path to the CheeseCake file is Cakes\CheeseCake
. Note how we are simply studying the file paths relative to the current working directory, C:\Recipes
.
Although relative paths hold less information than absolute paths, they are shorter and easier to work with (especially in deeply nested directories).
Free Resources