Python: Path one folder back???

Hi,

It seems to be a simple task but whatever I tried it didn’t work.

So how can I go a folder back?

this does not work:

bge.logic.expandPath('..\\//buildings\\libfile.blend')

Thanks in advance


Babe Asian

This might work (as usual, at work so can’t test it):


import os

cwd = os.getcwd()

backOne = os.path.dirname(cwd)

bge.logic.expandPath(backOne)

### Just for checking! ###
print cwd
print backOne


Check out the os.path module for more details on exploring directory structures

Hope this helps!

Give this a try:

bge.logic.expandPath('//../buildings/libfile.blend')

The “//” to start with denotes a relative path. Also, to keep things more portable and cross-platform use ‘/’ as the directory separator.

Hey thanks both of you for that useful information.

@battery
thanks for that great link, seems a bit complicated to find the right thing though.:confused:

@Moguri
Your code works wonderful. Thanks.
This must be the only thing I didn’t try. Must have missed that one.


Ship sale