Reputation: 1142
my question is pretty much what the title suggests. my research has led me to try something like this:
import os
pathname = os.path.abspath("some/relative/directory")
print pathname
this problem is that whenever i do something like this, it simply returns whatever relative directory i gave it preceded by my python directory. for example:
C:\Python27\some\relative\directory
which is not even an existing directory on my computer. i understand that the python interpreter searches the working directory by default, but what i'd like to do is have it search my entire computer for an absolute path that contains the partial directory i specify.
the purpose of this is for me to create an exe (using py2exe) that can search for an arbitrary directory on any computer. is there a method for doing this in the standard library or through some available module - or would i have to implement the algorithm myself?
Upvotes: 3
Views: 1203
Reputation: 12920
Did you try os.path.realpath("my/relative/dir")
? Actually it seems the directory may not exist, but if it does, it will resolve symbolic links and whatnot.
Upvotes: 0
Reputation: 284786
abspath
is based on getcwd
. Most likely, your current working directory simply isn't what you expect.
You can change the code that launches your script, change directories manually, or just use chdir
in Python.
Upvotes: 4