windows directories for curr user

Tim Golden tim.golden at viacom-outdoor.co.uk
Wed May 11 03:47:50 EDT 2005


[Dan Bishop]
| flamesrock wrote:
| > Hi,
| >
| > Short, maybe newbish question: Is there a python method for finding
| out
| > who the current user is in the OS module?
| >
| > On older windows machines the directory I'm interested in is just
| > "c://my documents", but how do I walk to the current users my
| documents
| > folder?
| 
| path = '%s\\My Documents' % os.environ['USERPROFILE']

Or, rather more generally:

<code>

from win32com.shell import shell, shellcon
import win32api
  
#
# Don't need this to find the right folder,
#  but since you asked...
#
print win32api.GetUserName ()

#
# This is the "personal files" which usually corresponds
#  to the "My Documents" folder, but in my case points to
#  h:\ since that's my home folder in my AD profile.
#
print shell.SHGetPathFromIDList (
  shell.SHGetSpecialFolderLocation (0, shellcon.CSIDL_PERSONAL)
)

#
# To see a list of possible CSIDL values:
#
for i in dir (shellcon):
  if i.startswith ("CSIDL"):
    print i

</code>


________________________________________________________________________
This e-mail has been scanned for all viruses by Star. 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