1. Absolute File Path 2. Relative File Path
The root is /.
Absolute file paths always start off relative to the root. It basically just starts from the origin (the root of the computer).
Example:
/work/report.doc
Relative file path looks in the current folder for the file.
. (single dot): current directory you are in.
.. (double dot): parent directory (the folder right above the current one).
For example:
Absolute file paths:
/work/project/main.py
-
If your current directory is
/work/project/, your relative path would be:./main.py -
If your current directory is
/work/, your relative path would be:./project/main.py
Note:
We can write the relative path without ./, like project/main.py
For each jump you need to use ../
For example if you are in :
- Windows :
F:\python\new-folder - Unix/Linux/macOS :
/F/python/new-folder(if 'F' were a folder name)
And your text.txt file is in the F directory :
../../test.txt"