Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #93660
| From | random832@fastmail.us |
|---|---|
| References | <mstorkamp-154B4A.09272010072015@88-209-239-213.giganet.hu> <20150710094607.66e62712@bigbox.christie.dr> |
| Subject | Re: Trouble getting to windows My Documents directory |
| Date | 2015-07-10 20:24 -0400 |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.408.1436574781.3674.python-list@python.org> (permalink) |
The My Documents directory is not guaranteed to be named "Documents". On
older versions of windows it was "My Documents", and on foreign versions
of windows it is a name in their language.
The correct way to get the path of this folder is, for example (couldn't
test since I'm on a mac right now)
import ctypes
from ctypes import wintypes
CSIDL_PERSONAL = 5
SHGetFolderPath = ctypes.windll.shell32.SHGetFolderPathW
pszPath = ctypes.create_unicode_buffer(wintypes.MAX_PATH)
SHGetFolderPath.argtypes = [wintypes.HWND, ctypes.c_int,
wintypes.HANDLE, wintypes.DWORD, LPWSTR]
SHGetFolderPath.restype = wintypes.HRESULT
hResult = SHGetFolderPath(0, CSIDL_PERSONAL, 0, 0, pszPath)
if hResult == 0:
print pszPath.value
else
raise OSError("Could not find My Documents directory")
Linux systems generally provide their own way to get it (e.g.
xdg-user-dirs), on OSX everything I can find indicates it really is
always ~/Documents .
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Trouble getting to windows My Documents directory Mark Storkamp <mstorkamp@yahoo.com> - 2015-07-10 09:27 -0500
Re: Trouble getting to windows My Documents directory Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-07-10 15:47 +0100
Re: Trouble getting to windows My Documents directory Laura Creighton <lac@openend.se> - 2015-07-10 17:11 +0200
Re: Trouble getting to windows My Documents directory MRAB <python@mrabarnett.plus.com> - 2015-07-10 16:12 +0100
Re: Trouble getting to windows My Documents directory Mark Storkamp <mstorkamp@yahoo.com> - 2015-07-10 10:25 -0500
Re: Trouble getting to windows My Documents directory Rustom Mody <rustompmody@gmail.com> - 2015-07-10 10:48 -0700
Re: Trouble getting to windows My Documents directory Rustom Mody <rustompmody@gmail.com> - 2015-07-10 10:56 -0700
Re: Trouble getting to windows My Documents directory Tim Chase <python.list@tim.thechases.com> - 2015-07-10 09:46 -0500
Re: Trouble getting to windows My Documents directory random832@fastmail.us - 2015-07-10 20:24 -0400
Re: Trouble getting to windows My Documents directory Chris Warrick <kwpolska@gmail.com> - 2015-07-11 09:28 +0200
Re: Trouble getting to windows My Documents directory Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-07-11 11:47 -0400
Re: Trouble getting to windows My Documents directory random832@fastmail.us - 2015-08-01 02:50 -0400
csiph-web