How to get relative ("../x") path between two files?

Viewed 37

My directory structure is:

root:.
[.]
┣━[foo1]
┃  ┣━[scripts]
┃  ┃  ┗━test.py
┣━[foo2]
  ┗━test1.txt

I call test.py from the scripts folder and pass the entire absolute path of test1.txt

How do I get the path of test1.txt relative to the path of test.py ?

Inputs: ./foo1/scripts/test.py and ./foo2/test1.txt

Expected output: ../../foo2/test.txt

0 Answers
Related