# How do I get the current directory without an open file?

I've done a lot of searches but unless I'm missing something obvious (and I may be) I don't see any answers that don't involve already having a Blender file open (and I understand how to do that).

What I'd like to do is in my script be able to access the current directory that Blender opens up to load in Blender files. BEFORE any file is loaded. Because that default directory is where I want to store a config file to read parameters for my script (which can be run even if they don't have opened a Blender file).

Does that make sense? I can force a directory, of course, but I'd rather say to folks "just put the config in your default Blender directory" and then be able to find that file there.

All the answers seem to require first a file, like these:

bpy.path.abspath("//my/file.txt")
bpy.path.abspath("//my\\file.txt")  # on Windows, with backslash escaped
bpy.path.abspath(r"//my\file.txt")  # on Windows, using python raw string
bpy.path.abspath("//../file.txt")  # to go back a directory


but I don't have a file. (And using the "//" alone gives me an error, although using two back slashes just gives me a single "\" as the result, which is NOT the current directory).

This seems stupidly simple but I'm feeling really dumb.

Shoot, here it is:

import os
os.getcwd()


But I looked for a couple of hours without luck. Sorry, folks.

• Those are not the same. //some/path.txt means "relative to the currently open blendfile". os.getcwd() will give you the current working directory, which isn't related to which blendfile is open at all (on Windows it'll most likely give you 'C:\\Program Files\\Blender Foundation\\Blender'). – dr. Sybren Jun 3 '18 at 9:17
• Yeah, I found that out later, but at least it gives me a workable place to point folks to that won't change on their systems (unlike the relative to currently open blendfile). I guess there isn't just a "show default dir where I will open up Blender files" way, but that's acceptable right now. – Mike Kelley Jun 4 '18 at 10:09
• That directory can't be written to by normal users, so it's rather pointless to send them there. Using os.path.expanduser('~') will give you the home directory of the user, which is much more likely to be what they want. – dr. Sybren Jun 4 '18 at 10:28
• Thanks, doc, that does seem to be better (I added a \\documents\\ to the path because that's a directory all should have there). This isn't so much for the world to use, so I wasn't too concerned about needing admin privileges, but it's definitely easier even for me not to have to invoke permissions each time. – Mike Kelley Jun 5 '18 at 17:01
• If you want cross-platform support, you can't assume there is a documents folder there, nor can you use backslashes. Maybe that's relevant to you, maybe not ;-) – dr. Sybren Jun 5 '18 at 17:13