Reputation: 5661
is there a function that translate relative path ../test.txt into a full path? example:
the full path is:
/Users/paganotti/Documents/Project/simple/work/paga/
the relative path is:
../test.txt
I want build this result:
/Users/paganotti/Documents/Project/simple/work/test.txt
As you can see translate ../ into "work" folder for build entire path.
Is there general function that acomplish this task?
Upvotes: 3
Views: 1612
Reputation: 229754
You can use normpath()
from the os.path
module to get a normalize path from one with ".."
and similar constructs:
base = '/Users/paganotti/Documents/Project/simple/work/paga/'
rel = '../test.txt'
print os.path.normpath(os.path.join(base, rel))
Upvotes: 1