Os.getwd() returns wrong directory in Rhino8?

The code below returns the path to the folder containing the running script document in Rhino7, which is what I expect. In Rhino8, it returns C:\Program Files\Rhino 8\System (my script is not in that folder).

Is it a bug? Is this just the new way going forward? Is there an alternate way to get the folder of the running script (or even the full path)?

#! python 2
import os
print(os.getcwd())

I generally need the python2 comment, but I get the same results with and without that comment.

import os
print(os.getcwd())

Thanks in advance!

cwd stands for current working directory, which may be just about anything, and change at any time

not sure how things work with scripts running in rhino, but you could try some of the various approaches here: python - How can I find script's directory? - Stack Overflow

1 Like

Thanks. os.path.dirname(__file__) seems to do the trick.

@webdunce

small remark; if you call os.getcwd() from inside a module, it is expected to return the directory of the __main__ entry script. Your solution will return the module directory instead.

instead you could use:

import sys
sys.path[0] 
1 Like