Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > RE: windows directories for curr user

Reply
Thread Tools

RE: windows directories for curr user

 
 
Tim Golden
Guest
Posts: n/a
 
      05-11-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
__________________________________________________ ______________________
 
Reply With Quote
 
 
 
 
flamesrock
Guest
Posts: n/a
 
      05-11-2005
Thanks for the code Tom.

Unforunately, I get the following error message when trying to import
win32com in idle:

>>> from win32com.shell import shell, shellcon


Traceback (most recent call last):
File "<pyshell#20>", line 1, in -toplevel-
from win32com.shell import shell, shellcon
ImportError: No module named win32com.shell

Tim Golden wrote:
> [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
>

__________________________________________________ ______________________

 
Reply With Quote
 
 
 
 
Peter Hansen
Guest
Posts: n/a
 
      05-11-2005
flamesrock wrote:
> Thanks for the code Tom.
>
> Unforunately, I get the following error message when trying to import
> win32com in idle:


Have you installed the pywin32 package? If not, see Google...
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
windows directories for curr user flamesrock Python 2 05-11-2005 06:27 AM
Can I finish MCSE NT 4 with curr electives and then use for MCSE 2 =?Utf-8?B?UmljaGFyZEs=?= MCSE 5 11-22-2004 01:33 PM
Multiple bin-directories with virtual directories? =?Utf-8?B?TGFzc2UgTmlsc3Nvbg==?= ASP .Net 0 11-09-2004 05:49 PM
How to map Project directories to Production sub-directories Joel Finkel ASP .Net 0 09-12-2003 06:47 PM
Using virtual directories for common directories (scripts, images, styles, etc.) Jeffry van de Vuurst ASP .Net 2 07-30-2003 07:00 PM



Advertisments