RE: Path ... where is my application's home dir?

Discussion in 'Python' started by Tim Golden, Apr 28, 2004.

  1. Tim Golden

    Tim Golden Guest

    >As I said: It is a windows machine, single user, small app... but I am
    >very glad you made this remarks, cause it reminds me to consider
    >portability when writing apps - and now I can see, where I am failing.
    >Thanks.
    >
    >And yes, the best place to store this information would be in
    >the user's
    >home dir, but then: Where is it? How to find it under Windows - every
    >version of windows changes the place for home dirs. It would
    >be nice to
    >have something like this in a system/version independet way:
    >
    >sys.users_home_dir
    >
    >Is there anything like it in Python?


    There's nothing that strictly does that. You could
    use os.path.expanduser ("~") but in Windows (at least
    on my Win2K box) it returns "c:/" which is just about
    acceptable for a one-user machine, but obviously not
    for multi-user.

    The usual way to do this on Windows is to use the
    winshell functions from pywin32:

    <code>
    from win32com.shell import shell, shellcon
    print shell.SHGetPathFromIDList (
    shell.SHGetSpecialFolderLocation (0, shellcon.CSIDL_APPDATA)
    )
    </code>

    which, on my machine, gives:

    C:\Documents and Settings\goldent\Application Data

    Conventionally, one creates a subdirectory of that
    directory, named after your application, and puts
    ..ini files and so on in there. This seems to be the
    way Microsoft has gone (thank goodness) and away from
    the registry.

    TJG


    ________________________________________________________________________
    This e-mail has been scanned for all viruses by Star Internet. 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, Apr 28, 2004
    #1
    1. Advertising

  2. Tim Golden

    Duncan Booth Guest

    Tim Golden <> wrote in
    news::

    >>And yes, the best place to store this information would be in
    >>the user's
    >>home dir, but then: Where is it? How to find it under Windows - every
    >>version of windows changes the place for home dirs. It would
    >>be nice to
    >>have something like this in a system/version independet way:
    >>
    >>sys.users_home_dir
    >>
    >>Is there anything like it in Python?

    >
    > There's nothing that strictly does that. You could
    > use os.path.expanduser ("~") but in Windows (at least
    > on my Win2K box) it returns "c:/" which is just about
    > acceptable for a one-user machine, but obviously not
    > for multi-user.
    >
    > The usual way to do this on Windows is to use the
    > winshell functions from pywin32:
    >
    ><code>
    > from win32com.shell import shell, shellcon
    > print shell.SHGetPathFromIDList (
    > shell.SHGetSpecialFolderLocation (0, shellcon.CSIDL_APPDATA)
    > )
    ></code>
    >
    > which, on my machine, gives:
    >
    > C:\Documents and Settings\goldent\Application Data


    A simpler way to get the same information:

    import os
    print os.environ['APPDATA']
    Duncan Booth, Apr 28, 2004
    #2
    1. Advertising

  3. Tim Golden

    Yermat Guest

    Duncan Booth a écrit :
    > Tim Golden <> wrote in
    > news::
    >
    >
    >>>And yes, the best place to store this information would be in
    >>>the user's
    >>>home dir, but then: Where is it? How to find it under Windows - every
    >>>version of windows changes the place for home dirs. It would
    >>>be nice to
    >>>have something like this in a system/version independet way:
    >>>
    >>>sys.users_home_dir
    >>>
    >>>Is there anything like it in Python?

    >>
    >>There's nothing that strictly does that. You could
    >>use os.path.expanduser ("~") but in Windows (at least
    >>on my Win2K box) it returns "c:/" which is just about
    >>acceptable for a one-user machine, but obviously not
    >>for multi-user.
    >>
    >>The usual way to do this on Windows is to use the
    >>winshell functions from pywin32:
    >>
    >><code>
    >>from win32com.shell import shell, shellcon
    >>print shell.SHGetPathFromIDList (
    >> shell.SHGetSpecialFolderLocation (0, shellcon.CSIDL_APPDATA)
    >>)
    >></code>
    >>
    >>which, on my machine, gives:
    >>
    >>C:\Documents and Settings\goldent\Application Data

    >
    >
    > A simpler way to get the same information:
    >
    > import os
    > print os.environ['APPDATA']
    >


    And for the user dir, you can do (at least on Win2000, not try elsewhere) :
    os.getenv('HOMEDRIVE') + os.getenv('HOMEPATH')

    --
    Yermat
    Yermat, Apr 28, 2004
    #3
  4. Tim Golden

    Peter Hansen Guest

    Yermat wrote:

    > Duncan Booth a écrit :
    > And for the user dir, you can do (at least on Win2000, not try elsewhere) :
    > os.getenv('HOMEDRIVE') + os.getenv('HOMEPATH')


    Also works on WinXP. (And the last statistic I saw showed Win98
    users at something like 2% of the Windows-using population,
    so perhaps we can almost forget about it... ?)

    -Peter
    Peter Hansen, Apr 28, 2004
    #4
  5. Tim Golden

    Yermat Guest

    Peter Hansen a écrit :

    > Yermat wrote:
    >
    >> Duncan Booth a écrit :
    >> And for the user dir, you can do (at least on Win2000, not try
    >> elsewhere) :
    >> os.getenv('HOMEDRIVE') + os.getenv('HOMEPATH')

    >
    >
    > Also works on WinXP. (And the last statistic I saw showed Win98
    > users at something like 2% of the Windows-using population,
    > so perhaps we can almost forget about it... ?)
    >
    > -Peter


    Good point !

    Browsing old messages from clp in google. It seems the only way to do
    this on win98 is to read it in the registry...

    --
    Yermat
    Yermat, Apr 28, 2004
    #5
  6. Tim Golden wrote:
    > The usual way to [get the application data folder] on Windows
    > is to use the winshell functions from pywin32:
    >
    > <code>
    > from win32com.shell import shell, shellcon
    > print shell.SHGetPathFromIDList (
    > shell.SHGetSpecialFolderLocation (0, shellcon.CSIDL_APPDATA)
    > )
    > </code>
    >
    > which, on my machine, gives:
    >
    > C:\Documents and Settings\goldent\Application Data
    >
    > Conventionally, one creates a subdirectory of that
    > directory, named after your application, and puts
    > .ini files and so on in there. This seems to be the way
    > Microsoft has gone (thank goodness) and away from
    > the registry.


    Yes, that is the right place for a Windows application to store its data,
    with one caveat. On a system that uses a "roaming profile" as used in some
    corporate settings, the entire Application Data folder gets copied down from
    a server when the user logs in, and copied back up to the server when the
    user logs out. So, this folder is the right place for small things like
    settings files, but not for large amounts of data that should be kept on the
    local machine.

    There is another folder, the local application data folder, where large
    files should be kept. For example, Outlook and Outlook Express keep their
    databases in the local application data folder. You can get the path to this
    folder with the same code as above by changing CSIDL_APPDATA to
    CSIDL_LOCAL_APPDATA.

    However, Win98/Me/NT4 do not support CSIDL_LOCAL_APPDATA, so you'll need to
    check for an error return and fall back to CSIDL_APPDATA on those system. (I
    don't know how SHGetSpecialFolderLocation indicates an error--the docs don't
    say--maybe it raises an exception or returns an error value?)

    -Mike
    Michael Geary, Apr 28, 2004
    #6
  7. Tim Golden

    JanC Guest

    Peter Hansen <> schreef:

    > Also works on WinXP. (And the last statistic I saw showed Win98
    > users at something like 2% of the Windows-using population,
    > so perhaps we can almost forget about it... ?)


    I guess Win9x users are more like 15-30% of the Windows-using population...

    --
    JanC

    "Be strict when sending and tolerant when receiving."
    RFC 1958 - Architectural Principles of the Internet - section 3.9
    JanC, Apr 30, 2004
    #7
  8. Tim Golden

    Peter Hansen Guest

    JanC wrote:

    > Peter Hansen <> schreef:
    >
    >
    >>Also works on WinXP. (And the last statistic I saw showed Win98
    >>users at something like 2% of the Windows-using population,
    >>so perhaps we can almost forget about it... ?)

    >
    >
    > I guess Win9x users are more like 15-30% of the Windows-using population...


    No doubt the answer is somewhere in between 2% and "15-30%", but
    mine was not a guess, just an actual survey. (No, I don't have
    a reference for it... wasn't important for me to save it at the
    time and I've personally migrated to XP, so now of course the
    rest of the world that hasn't is of less interest to me. ;-)

    -Peter
    Peter Hansen, Apr 30, 2004
    #8
  9. Tim Golden

    Jorge Godoy Guest

    On Sex 30 Abr 2004 08:53, Peter Hansen wrote:

    > No doubt the answer is somewhere in between 2% and "15-30%", but
    > mine was not a guess, just an actual survey. (No, I don't have
    > a reference for it... wasn't important for me to save it at the
    > time and I've personally migrated to XP, so now of course the
    > rest of the world that hasn't is of less interest to me. ;-)


    I hope one day I can think like that... Until there, I have to worry about
    what the clients use :-(


    --
    Godoy. <>
    Jorge Godoy, Apr 30, 2004
    #9
  10. Tim Golden

    Roger Binns Guest

    JanC wrote:
    > I guess Win9x users are more like 15-30% of the Windows-using population...


    Here is some stats from my web server where I host a FAQ for a US based
    cellphone. Obviously mileage may vary by country (and cell phone
    ownership :)

    XP 59.3%
    2000 19.3%
    NT 1.2%
    Me 2.6%
    CE 0.0% (45 hits total!)
    98 6.7%
    95 0.2%
    2003 0.2%

    The numbers don't add up to 100, as there are hits from Mac (total 3.8%)
    Linux (1.2%) and Unknown (4.8%) plus a random smattering of others
    (eg WebTV and OS/2)

    You can compare with Google where you can see their worldwide figures
    for March: http://www.google.com/press/zeitgeist.html
    They have 22% for Windows 98, which seems to take proportionally
    from the figures in my stats.

    Of course we don't know what percentage of people configure their
    browsers to lie.

    Roger
    Roger Binns, May 2, 2004
    #10
  11. Tim Golden

    JanC Guest

    "Roger Binns" <> schreef:

    > You can compare with Google where you can see their worldwide figures
    > for March: http://www.google.com/press/zeitgeist.html
    > They have 22% for Windows 98, which seems to take proportionally
    > from the figures in my stats.


    At least, they are pretty close to my guess... :)

    > Of course we don't know what percentage of people configure their
    > browsers to lie.


    And:
    - what percentage of people have a PC and no internet access...
    - what percentage have a PC & internet at work but aren't allowed to use it
    for visiting your site (or other non-work-related sites).
    - etc.

    --
    JanC

    "Be strict when sending and tolerant when receiving."
    RFC 1958 - Architectural Principles of the Internet - section 3.9
    JanC, May 3, 2004
    #11
  12. Tim Golden

    Peter Hansen Guest

    JanC wrote:

    > "Roger Binns" <> schreef:
    >>You can compare with Google where you can see their worldwide figures
    >>for March: http://www.google.com/press/zeitgeist.html
    >>They have 22% for Windows 98, which seems to take proportionally
    >>from the figures in my stats.

    >
    > At least, they are pretty close to my guess... :)
    >
    >>Of course we don't know what percentage of people configure their
    >>browsers to lie.

    >
    > And:
    > - what percentage of people have a PC and no internet access...
    > - what percentage have a PC & internet at work but aren't allowed to use it
    > for visiting your site (or other non-work-related sites).
    > - etc.


    And, finally, what percentage of any of these subsets are likely
    customers for Jorge, Yermat, you or me? ;-)

    (It likely includes very few of those with a PC but no internet
    access and, I would propose, it also includes only a small subset
    of those still stuck with Win98.)

    -Peter
    Peter Hansen, May 3, 2004
    #12
    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. =?Utf-8?B?UnVkeQ==?=

    Sub Dir, Virtual dir, what do I use?

    =?Utf-8?B?UnVkeQ==?=, Jun 12, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    412
    =?Utf-8?B?UnVkeQ==?=
    Jun 12, 2005
  2. Marco Aschwanden

    Path ... where is my application's home dir?

    Marco Aschwanden, Apr 28, 2004, in forum: Python
    Replies:
    6
    Views:
    450
    Roger Binns
    May 2, 2004
  3. Matthew Denner
    Replies:
    1
    Views:
    158
  4. Kga Agk
    Replies:
    2
    Views:
    138
    Kga Agk
    Jun 29, 2009
  5. Nick Gnedin
    Replies:
    2
    Views:
    148
Loading...

Share This Page