Finding the "home" folder [Linux/Windows]

L

Luca T.

Hello,
i need a way to find the home folder of the current user no matter if i am
in Linux or Windows for instance:
* Linux: /home/username
* Windows: C:\Documents and Settings\username

[of course this might change]

Is there any general way to do this?

Thank you,
Luca
 
M

Mike C. Fletcher

There's some code in OpenGLContext to do something like this (though
it's getting the user's application-data directory, not their "home"
directory):

http://cvs.sourceforge.net/viewcvs.py/pyopengl/OpenGLContext/browser/homedirectory.py?view=markup

You'll want to use one of the other shellcon.CSIDL_* constants and
something other than 'AppData' to get the "home" directory (whatever
that means) and will want to figure out something for Win9x. On Windows
AFAIK there really isn't a home directory concept, BTW, you're supposed
to store different types of things in different directories.

HTH,
Mike

Hello,
i need a way to find the home folder of the current user no matter if i am
in Linux or Windows for instance:
* Linux: /home/username
* Windows: C:\Documents and Settings\username

[of course this might change]

Is there any general way to do this?

Thank you,
Luca
_______________________________________
Mike C. Fletcher
Designer, VR Plumber, Coder
http://members.rogers.com/mcfletch/
 
T

Trent Mick

[Luca T. wrote]
On Linux you can just get the HOME environment variable value or just
use:
os.path.expanduser("~")

On Windows, as Mike said, "you're supposed to store difference types of
things in different directories". Here is a description of those
difference directories as MS defines them:

http://msdn.microsoft.com/library/d...llcc/platform/shell/reference/enums/csidl.asp

The CSIDL_* flags are values that meant to passed to the Win32 API call:

SHGetFolderPath()

If you have PyWin32 (aka win32all) installed in your Python installation
then you can do this:

from win32com.shell import shellcon, shell
path = shell.SHGetFolderPath(0, shellcon.CSIDL_*, 0, 0)

Cheers,
Trent
 
A

Andrew

dont forget the different windows operating systems:

windows 98/me: c:\my documents\username
windows NT: c:\winnt\profiles\username
windows xp/2k: c:\documents and settings\username

you might have to check the OS type and version, and go from there...

-andrew

Hello,
i need a way to find the home folder of the current user no matter if i
am
in Linux or Windows for instance:
* Linux: /home/username
* Windows: C:\Documents and Settings\username

[of course this might change]

Is there any general way to do this?

Thank you,
Luca
 
A

Andrew Chin

true.. in that case i suppose the 'home directory' would be simply 'c:\my
documents\'
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top