Here’s a list of how directories and file paths work in most programming environments:
Relative Paths
./name.txt
:
Refers to the filename.txt
in the current directory.../name.txt
:
Refers to the filename.txt
in the parent directory of the current folder.../../name.txt
:
Refers to the filename.txt
two levels up from the current folder../folder/name.txt
:
Refers to the filename.txt
inside the subfolderfolder
in the current directory.../folder/name.txt
:
Refers to the filename.txt
inside the subfolderfolder
in the parent directory.
Absolute Paths
/name.txt
:
Refers to the filename.txt
in the root directory (applicable in Unix-like systems).C:\folder\name.txt
:
Refers to the filename.txt
in the folderfolder
on theC:
drive (Windows-specific).
Special Cases
~
:
Refers to the home directory of the current user (e.g.,/home/username
orC:\Users\username
).name.txt
:
A plain filename without a relative (./
) or absolute (/
) prefix usually defaults to current directory, but its resolution depends on the environment.
Path Normalization
Different path notations (/
vs \
) matter based on the operating system:
Unix/Linux/MacOS: Use
/
as the path separator.Windows: Use
\
as the path separator but most Node.js modules (likepath
) can handle/
as well.