By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,089 Members | 2,432 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,089 IT Pros & Developers. It's quick & easy.

where should config files go in Windows?

P: n/a
I'm writing a cross-platform app. Presently it runs on unix and MacOS X,
but eventually I'd like to get it working on Windows (nothing older than
2000).

For unix and MacOS X I store settings in ~/.TUIPrefs and ~/.TUIGeom and
allow extensions to be stored in ~/TUIAdditions/ and <app's parent
dir>/TUIAdditions/.

Is the home dir easily accessible from vanilla Python (and if so, how do
I get there)? Is there a better directory (I'm really not keen to mess
with the registry) or some special add-on library that I'll need?

Also, is there something simple like unix's leading "." that makes
Windows files invisible?

Any help appreciated. I tried google and found this topic discussed
several years ago, but the answers were confusing and didn't seem to
apply to current Windows.

-- Russell
Jul 18 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Russell E. Owen wrote:
....
For unix and MacOS X I store settings in ~/.TUIPrefs and ~/.TUIGeom and
allow extensions to be stored in ~/TUIAdditions/ and <app's parent
dir>/TUIAdditions/.

Is the home dir easily accessible from vanilla Python (and if so, how do
I get there)? Is there a better directory (I'm really not keen to mess
with the registry) or some special add-on library that I'll need?

There are actually multiple directories for this kind of thing,
depending on whether you're describing user's documents,
application-specific data for the user (e.g. custom dictionaries),
common application-specific data (app-specific system dictionaries),
etceteras. You can see an example of retrieving the user's
application-specific data directory here:

http://cvs.sourceforge.net/viewcvs.p...py?view=markup

using either of _winreg (standard module) or win32com's shell (common
add-on, part of win32all).

See the MSDN documentation for the various folders which are defined.

http://msdn.microsoft.com/library/de...folderpath.asp
Also, is there something simple like unix's leading "." that makes
Windows files invisible?

Haven't tried to do this myself. But then I hate "hidden" files enough
to simply disable hiding them in the explorer, so who knows, maybe I
hide them all the time :) . On windows it's more common to just put the
file in the correct directory, where they are "out of the way", instead
of dumping them into a "home" directory and hiding them.

Good luck,
Mike

_______________________________________
Mike C. Fletcher
Designer, VR Plumber, Coder
http://members.rogers.com/mcfletch/

Jul 18 '05 #2

P: n/a
I use the following for multi-platform home directories in my own
project http://pype.sourceforge.net

I've had no complaints from people using *nix or Windows. I haven't
heard of any users on macs yet, so have no comment.

- Josiah
default_homedir = os.path.dirname(os.path.abspath(__file__))
dotpath = '.application_name'

try:
#all user-based OSes
thd = os.path.expanduser("~")
if thd == "~": raise
homedir = os.path.join(thd, dotpath)
except:
try:
#*nix fallback
homedir = os.path.join(os.environ['HOME'], dotpath)
except:
try:
#windows NT,2k,XP,etc. fallback
homedir = os.path.join(os.environ['USERPROFILE'], dotpath)
except:
#What os are people using?
homedir = os.path.join(default_homedir, dotpath)
try:
# create the config directory if it
# doesn't already exist
def expandfull(var, rem=3):
if not rem:
return os.path.expandvars(var)
a = os.path.expandvars(var)
b = []
d = [b.extend(i.split('\\')) for i in a.split('/')]
c = []
for i in b:
if '%' in i:
c.append(expandfull(i, rem-1))
else:
c.append(i)
return '\\'.join(c)
if eol == "\r\n" and '%' in homedir:
homedir = expandfull(homedir)
if not os.path.exists(homedir):
os.mkdir(homedir)
except:
#print "unable to create config directory", homedir
homedir = default_homedir
Jul 18 '05 #3

P: n/a
In article <ma***************************************@python. org>,
"Mike C. Fletcher" <mc******@rogers.com> wrote:
Russell E. Owen wrote:
...
(essentially I asked where prefs and application-specific data go on Windows)

There are actually multiple directories for this kind of thing,
depending on whether you're describing user's documents,
application-specific data for the user (e.g. custom dictionaries),
common application-specific data (app-specific system dictionaries),
etceteras. You can see an example of retrieving the user's
application-specific data directory here:

http://cvs.sourceforge.net/viewcvs.p...ser/homedirect
ory.py?view=markup

using either of _winreg (standard module) or win32com's shell (common
add-on, part of win32all).

See the MSDN documentation for the various folders which are defined.

http://msdn.microsoft.com/library/de...shellcc/platfo
rm/shell/reference/functions/shgetfolderpath.asp


Thank you very much! That's just what I wanted. I'll put preferences
<AppData>\TUIPrefs, optional user additions in <AppData>\TUIAdditions
and optional shared additions in <Common_AppData>\TUIAdditions. There
are equivalent standard directories on MacOS X (easily found; code
available on request). For unix I'll use ~/.TUIPrefs, ~/TUIAdditions and
(for lack of a better place), shared additions in
<tui_root>/TUIAdditions, where <tui_root> is the folder containing the
app's code.

-- Russell
Jul 18 '05 #4

P: n/a
> >See the MSDN documentation for the various folders which are defined.

http://msdn.microsoft.com/library/de...-us/shellcc/pl

atform/shell/reference/functions/shgetfolderpath.asp
Thank you very much! That's just what I wanted. I'll put preferences
<AppData>\TUIPrefs, optional user additions in <AppData>\TUIAdditions
and optional shared additions in <Common_AppData>\TUIAdditions.


I'd like to suggest creating only a single folder under Application Data,
with additional folders inside it for your specific needs. The usual
convention is to create a folder with your company name, then additional
folders inside that for each product, and finally folders inside those for
things like your TUIPrefs and TUIAdditions.

Also, make careful note of the difference between Application Data and Local
Settings\Application Data. On most machines, it doesn't matter which of
those you use. But if someone uses "roaming profiles", then you need to
choose which of those folders to use. Application Data is part of the
roaming profile, and it gets copied from a server when the user logs in, and
back to the server when the user logs out. Local Settings\Application Data
resides strictly on the local machine.

-Mike
Jul 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.