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

Michael Geary Mike at DeleteThis.Geary.com
Wed Apr 28 15:52:42 EDT 2004


Tim Golden wrote:
> The usual way to [get the application data folder] 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.

Yes, that is the right place for a Windows application to store its data,
with one caveat. On a system that uses a "roaming profile" as used in some
corporate settings, the entire Application Data folder gets copied down from
a server when the user logs in, and copied back up to the server when the
user logs out. So, this folder is the right place for small things like
settings files, but not for large amounts of data that should be kept on the
local machine.

There is another folder, the local application data folder, where large
files should be kept. For example, Outlook and Outlook Express keep their
databases in the local application data folder. You can get the path to this
folder with the same code as above by changing CSIDL_APPDATA to
CSIDL_LOCAL_APPDATA.

However, Win98/Me/NT4 do not support CSIDL_LOCAL_APPDATA, so you'll need to
check for an error return and fall back to CSIDL_APPDATA on those system. (I
don't know how SHGetSpecialFolderLocation indicates an error--the docs don't
say--maybe it raises an exception or returns an error value?)

-Mike





More information about the Python-list mailing list