RE: windows directories for curr user

Discussion in 'Python' started by Tim Golden, May 11, 2005.

  1. Tim Golden

    Tim Golden Guest

    [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
    ________________________________________________________________________
     
    Tim Golden, May 11, 2005
    #1
    1. Advertising

  2. Tim Golden

    flamesrock Guest

    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
    >

    ________________________________________________________________________
     
    flamesrock, May 11, 2005
    #2
    1. Advertising

  3. Tim Golden

    Peter Hansen Guest

    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...
     
    Peter Hansen, May 12, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Joel Finkel
    Replies:
    0
    Views:
    498
    Joel Finkel
    Sep 12, 2003
  2. Jeffry van de Vuurst
    Replies:
    2
    Views:
    539
    Jeffry van de Vuurst
    Jul 30, 2003
  3. =?Utf-8?B?TGFzc2UgTmlsc3Nvbg==?=

    Multiple bin-directories with virtual directories?

    =?Utf-8?B?TGFzc2UgTmlsc3Nvbg==?=, Nov 9, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    832
    =?Utf-8?B?TGFzc2UgTmlsc3Nvbg==?=
    Nov 9, 2004
  4. flamesrock

    windows directories for curr user

    flamesrock, May 11, 2005, in forum: Python
    Replies:
    2
    Views:
    253
    flamesrock
    May 11, 2005
  5. Paul F
    Replies:
    4
    Views:
    642
    Mark Fitzpatrick
    Jun 25, 2008
Loading...

Share This Page