Hi, friends!
Excuse me for offtopic
Under posix compatible OSes I can acquire path to user home dir by:
os.path.expanduser('~')
and how I can achieve the same thing under Windows 2000/XP?
···
--
Basil Shubin
Freelance Software Developer
Hi, friends!
Excuse me for offtopic
Under posix compatible OSes I can acquire path to user home dir by:
os.path.expanduser('~')
and how I can achieve the same thing under Windows 2000/XP?
--
Basil Shubin
Freelance Software Developer
Depends on if you want the directory stated by the %HOME% env var or if you want the “windows home dir” which is something like c:\documents and settings<username>.
The first is easy:
import os
if “HOME” in os.environ:
print os.environ[“HOME”]
else:
print “home is not defined”
The second one is all about asking the registry. Example code can be found here were all “user” folders are extracted from the registry:
save that file and use it like this to display all user specific folders:
from ShellFolders import fetchShellFolders
folders = fetchShellFolders()
for key in folders.keys():
print “%s: %s” % (key, folders[key])
Hope this helps,
–
Rune Devik
http://www.garageinnovation.org
On 10/26/06, Basil Shubin bashu@yandex.ru wrote:
Hi, friends!
Excuse me for offtopic
Under posix compatible OSes I can acquire path to user home dir by:
os.path.expanduser('~')
and how I can achieve the same thing under Windows 2000/XP?
–
Basil Shubin
Freelance Software Developer
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail:
wxPython-users-help@lists.wxwidgets.org
Basil Shubin wrote:
Hi, friends!
Excuse me for offtopic
Under posix compatible OSes I can acquire path to user home dir by:
os.path.expanduser('~')and how I can achieve the same thing under Windows 2000/XP?
Hi Basil,
have you tried to use it?
When I tried it, it returned a home path, but according the Python
documentation it depends on some environment variables that are set.
The documentation has some more information about it:
Cheers,
Guenter
Basil Shubin wrote:
Hi, friends!
Excuse me for offtopic
Under posix compatible OSes I can acquire path to user home dir by:
os.path.expanduser('~')
and how I can achieve the same thing under Windows 2000/XP?
Hi Basil,
have you tried to use it?
When I tried it, it returned a home path, but according the Python
documentation it depends on some environment variables that are set.
The HOME env var must be set for this to work. Didn’t know about that one though… cool stuff
On 10/26/06, Guenter Dannoritzer dannoritzer@web.de wrote:
The documentation has some more information about it:
http://docs.python.org/lib/module-os.path.htmlCheers,
Guenter
To unsubscribe, e-mail:
wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org
–
Rune Devik
http://www.garageinnovation.org
Maybe wx.StandardPaths() is what you need?
Phil
At 06:38 AM 10/26/2006, you wrote:
Hi, friends!
Excuse me for offtopic
Under posix compatible OSes I can acquire path to user home dir by:
os.path.expanduser('~')and how I can achieve the same thing under Windows 2000/XP?
Not a Win expert here, but this is what I'm using to determine the application data directory on both *nix and win32.
I know there is another variable than APPDATA you can query for. Maybe someone else more WIN32 savy can help out there.
I think the below code was from the python-cookbook
Hope that helps
Uwe
"""Attempt to determine the current user's "system" directories"""
try:
from win32com.shell import shell, shellcon
except ImportError:
shell = None
try:
import _winreg
except ImportError:
_winreg = None
## The registry keys where the SHGetFolderPath values appear to be stored
r"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders"
r"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders"
def appdatadirectory():
"""Attempt to retrieve the current user's app-data directory
This is the location where application-specific
files should be stored. On *nix systems, this will
be the HOME directory. On Win32 systems, it will be
the "Application Data" directory. Note that for
Win32 systems it is normal to create a sub-directory
for storing data in the Application Data directory.
XXX should os.environ['home'] override Win32 queries or
vice-versa?
"""
if shell:
# on Win32 and have Win32all extensions, best-case
return shell.SHGetFolderPath(
0,# null hwnd
shellcon.CSIDL_APPDATA, # the (roaming) appdata path
0,# null access token (no impersonation)
0 # want current value, shellcon.SHGFP_TYPE_CURRENT isn't available, this seems to work
)
if _winreg:
# on Win32, but no Win32 shell com available, this uses
# a direct registry access, likely to fail on Win98/Me
k = _winreg.OpenKey(
_winreg.HKEY_CURRENT_USER,
r"Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders"
)
try:
# should check that it's valid? How?
return _winreg.QueryValueEx( k, "AppData" )[0]
finally:
_winreg.CloseKey( k )
# okay, what if for some reason _winreg is missing? would we want to allow ctypes?
# default case, look for name in environ...
for name in ['appdata', 'home']:
if os.environ.has_key( name ):
return os.environ[name]
# well, someone's being naughty, see if we can get ~ to expand to a directory...
possible = os.path.abspath(os.path.expanduser( '~/' ))
if os.path.exists( possible ):
return possible
raise OSError( """Unable to determine user's application-data directory""" )
On Thursday 26 October 2006 06:38, Basil Shubin wrote:
Hi, friends!
Excuse me for offtopic
Under posix compatible OSes I can acquire path to user home dir by:
os.path.expanduser('~')and how I can achieve the same thing under Windows 2000/XP?
--
UC
--
Open Source Solutions 4U, LLC 1618 Kelly St
Phone: +1 707 568 3056 Santa Rosa, CA 95401
Cell: +1 650 302 2405 United States
Fax: +1 707 568 6416
Basil Shubin wrote:
Hi, friends!
Excuse me for offtopic
Under posix compatible OSes I can acquire path to user home dir by:
os.path.expanduser('~')and how I can achieve the same thing under Windows 2000/XP?
Depending on what you need the home dir for, you may want to use one of the wx.StandardPaths methods.
--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!
Robin Dunn пишет:
Basil Shubin wrote:
Hi, friends!
Excuse me for offtopic
Under posix compatible OSes I can acquire path to user home dir by:
os.path.expanduser('~')and how I can achieve the same thing under Windows 2000/XP?
Depending on what you need the home dir for, you may want to use one of the wx.StandardPaths methods.
Haha! wx.StandardPaths is much better then os.path.expanduser('~') !
--
Basil Shubin
Freelance Software Developer