Absolute vs Relative Path – Difference and Comparison

What is an Absolute Path?

An absolute path is a path that defines the position of a folder or a file. It points to a precise location in the file system. It is known as a file path. It is used to link content from another website

The absolute path includes the complete location of the folder or file, including which drive it is on. It is also denoted as an absolute full path. It begins from the root directory.

When it comes to URLs an absolute URL every time it points to the precise location of the web and it hold all the essential information. The absolute path contains all the relevant information to find the resources.

Different operating system (Windows, Linux, Mac os, etc.) uses different syntax to write an absolute path.

Several characters are involved in the absolute path that carries a different meaning in the computer language such as a single “\” or “/” mean directory separator.

For example, C:\sample\Picture and index in the path for pictures are C:\sample\Pictures.

What is a Relative Path?

It defines the place of a folder or file relative to the existing working directory. A relative path contains data that is only relative to the existing document within the same website which ignores the need to provide a full absolute path. It helps the developers in writing lengthy code.

In simple terms, a relative path means a path relative to the position of the existing page.

Based on URL relative path is easier to use because they are relative to the page they are on it, a relative path is a URL that contains a portion of the full path. It is alternatively denoted to as a non-absolute path or partial path. On windows, the relative path holds a partial address of the absolute path based on its relation with the directory to which it’s connected.

 A Relative pathway begins with “..” representing the parent directory and the tickles down to the specific location. However, they are much shorter than the full pathway.

Relative path writes it concerning another point in the file system. It must be combined with another path in other to access the file. It is also known as the non-absolute path or partial pathway.

Difference Between Absolute Path and Relative Path

  1. The absolute path specifies the locations from the root directory, whereas the relative path is related to the current directory.
  2. The absolute path always includes the domain name of the websites, including http://www., whereas relative links only point to a folder or a folder path.
  3. An absolute path is the exact address of the file in the file system starting from the root, whereas relative file write is with respect to another point in the file system.
  4. An absolute path starts with delaminating characters whereas a relative path never begins with a delaminating character.
  5. The absolute path uses an absolute URL whereas the relative part used a URL.
  6. An absolute path starts with “/” or “\” but a relative path never starts with “/” or “\”.

Comparison Between Absolute Path and Relative Path

Parameters of ComparisonAbsolute PathRelative Path
DefinitionIt specifies the location from the root directory.It specifies or relate the current from the directory.
Used of URLUses absolute URLUses relative URL
ReferredAbsolute path is known as full path or file path.The relative path is known as a non-absolute path.
PointsIt points to a particular location in the file system, regardless of the current working directory.It points to the position of a directory using the present directory as a reference.
ExampleIf our picture is in C:\sample\ picture and index in the path for pictures is c:\sample\picture.If your picture is in c:\sample\picture and index in c:\ Sample\Index, the relative path is “..\pictures”.

References

  1. https://aip.scitation.org/doi/abs/10.1063/1.1793931
  2. https://www.sciencedirect.com/science/article/pii/0095895682900363