Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Get Documents path from appex
-
The
os.path.expanduser("~/Documents")
trick doesn't work from the app extension. Is there another way?
-
If the script that you're running is in ~/Documents itself, you could get the path like this:
import os docs_path = os.path.split(__file__)[0]
-
Right. Forgot about
__file__
. Since it's not in Documents, but in a subdirectory, I should be able to do a find. -
Here's something that should also work in subfolders:
import os comps = __file__.split(os.sep) doc_path = os.sep.join(comps[:comps.index('Documents')+1])
-
@omz thanks. I had just come up with this
def getPath(): split=__file__.split('/') path=split[:split.index('Documents')+1] return '/'.join(path)
Yours is much cleaner :)
EDIT: oh wow, I just realized yours is almost exactly the same thing. I glanced at it and thought "Oh, it uses lots of os.path functions that I didn't know existed," but looking again it's basically exactly like my solution except using os.sep :)