user915783
user915783

Reputation: 699

relative path in python few folders up

I have following folder structure on Win7 machine:

C:\dev\bin\toplevel\python

I am running a script, say p1.py in this folder. I need to create folder termed Myscript under

C:\dev\matlab\scripts

I need to use path relative to my current folder \python. I tried using:

LibPathTst= '.\\dev\matlab\\scripts'
  os.makedirs(LibPathTst)

but this creates:

C:\dev\bin\toplevel\python\dev\matlab\scripts

Any help?

Upvotes: 1

Views: 2355

Answers (1)

Krumelur
Krumelur

Reputation: 32497

../../../matlab/scripts

Should be what you are looking for. Since you are using python, os.path.relpath (with the two paths as arts) gives you this result.

In a directory, there are two "special" nodes: "." and "..", pointing to the current directory and the parent directory, respectively.

Upvotes: 4

Related Questions