Path ... where is my application's home dir?

Tim Golden tim.golden at viacom-outdoor.co.uk
Wed Apr 28 11:01:15 EDT 2004


>As I said: It is a windows machine, single user, small app... but I am 
>very glad you made this remarks, cause it reminds me to consider 
>portability when writing apps - and now I can see, where I am failing. 
>Thanks.
>
>And yes, the best place to store this information would be in 
>the user's 
>home dir, but then: Where is it? How to find it under Windows - every 
>version of windows changes the place for home dirs. It would 
>be nice to 
>have something like this in a system/version independet way:
>
>sys.users_home_dir
>
>Is there anything like it in Python?

There's nothing that strictly does that. You could
use os.path.expanduser ("~") but in Windows (at least
on my Win2K box) it returns "c:/" which is just about
acceptable for a one-user machine, but obviously not
for multi-user.

The usual way to do this on Windows is to use the
winshell functions from pywin32:

<code>
from win32com.shell import shell, shellcon
print shell.SHGetPathFromIDList (
  shell.SHGetSpecialFolderLocation (0, shellcon.CSIDL_APPDATA)
)
</code>

which, on my machine, gives:

C:\Documents and Settings\goldent\Application Data

Conventionally, one creates a subdirectory of that
directory, named after your application, and puts
.ini files and so on in there. This seems to be the
way Microsoft has gone (thank goodness) and away from
the registry.

TJG


________________________________________________________________________
This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________




More information about the Python-list mailing list