DEV Community

Richie Moluno
Richie Moluno

Posted on

Relative and Absolute Paths

WHAT ARE PATHS

A path is a slash-separated list of directory names followed by either a directory name or a file name. Paths are similar to directories, a directory refers to a folder on a computer which has relationship with other folders within and around it.
A path can be classified into Relative paths and Absolute paths.

RELATIVE PATHS
As the name suggests, it is a path relative to the current working directory. Relative paths make use of some special symbols (. and ..) which refer to the current directory and the parent directory. Since directories are hierarchical these symbols are used in moving up in the hierarchy.
One major drawback of relative paths is, for instances where we want to move a document or file, we'll have to move the referenced data too

ABSOLUTE PATHS
An Absolute Path is a full path specifying the location of a file or directory, The specialty of this pathway is that it begins from the root directory and leads to the locations i.e it is specified from the root directory or the start of the filesystem.

Below is an example to illustrate how relative and absolute paths work.

  • C:
    • Desktop
    • Scripts
      • NewFolder
        • name.txt
      • maindistro
    • Files

In this case C: is the root directory, considering a case where we're working from the "Scripts" folder and we want to access the name.txt file, the relative path would be ./NewFolder/name.txt, but the absolute path would start from the root directory which is C: so it'll be C:/Scripts/NewFolder/name.txt

Top comments (0)