|
|
|
|
|
|
| Author |
Message |
Sreeram Kandallu *nix forums addict
Joined: 02 Jun 2006
Posts: 58
|
Posted: Tue Jul 18, 2006 3:33 pm Post subject:
getting user's home directory on windows
|
|
|
Hi everybody,
I'm having trouble using os.path.expanduser('~') on windows. It uses
$HOME or ($HOMEDRIVE+$HOMEPATH), but this doesn't work with windows
machines which are part of a domain. On such machines, the HOME envvar
may not be set at all, and the HOMEPATH envvar may be set to '\\'!!
Here's an implementation of getHomeDir which tries to find the best
possible option. I don't know how this'll behave on older versions of
windows such as win2k or win98. Please let me know if anybody knows a
better way to do this :
def getHomeDir() :
if sys.platform != 'win32' :
return os.path.expanduser( '~' )
def valid(path) :
if path and os.path.isdir(path) :
return True
return False
def env(name) :
return os.environ.get( name, '' )
homeDir = env( 'USERPROFILE' )
if not valid(homeDir) :
homeDir = env( 'HOME' )
if not valid(homeDir) :
homeDir = '%s%s' % (env('HOMEDRIVE'),env('HOMEPATH'))
if not valid(homeDir) :
homeDir = env( 'SYSTEMDRIVE' )
if homeDir and (not homeDir.endswith('\\')) :
homeDir += '\\'
if not valid(homeDir) :
homeDir = 'C:\\'
return homeDir
[sreeram;]
ps:
A bit of googling around got me this informative post:
http://www.mail-archive.com/bug-cvs@gnu.org/msg05565.html |
|
| Back to top |
|
 |
Google
|
|
| Back to top |
|
 |
|
|
The time now is Thu Jan 08, 2009 6:52 am | All times are GMT
|
|
Repair Bad Credit | Internet Dating | Loans | Ringtones | Credit Counseling
|
|
Copyright © 2004-2005 DeniX Solutions SRL
|
|
|
|
Other DeniX Solutions sites:
Unix/Linux blog |
electronics forum |
medicine forum |
science forum |
|
|
Privacy Policy
|
Powered by phpBB © 2001, 2005 phpBB Group
|
|