Python: compute relative path from one directory to another

Possible duplicate:
How to calculate the relative path between two directories?

I need to calculate the relative path from one directory to another (i.e. I set the path relative to the working directory and want to calculate the corresponding relative path from any parent / subdir). What is a good way to do this in Python? I could not find much on this subject.

Thanks!

+6
source share
3 answers

You should take a look at: os.path.relpath

+10
source

os.path.relpath () does this for you and is available in Python 2.6 and later.

+4
source

You can set the relative path using os.path.dirname ( file )

os.path.join (os.path.dirname ( file ), "filename")

-1
source

Source: https://habr.com/ru/post/904329/


All Articles