This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Get path to shell/known folders on Windows
Type: enhancement Stage: patch review
Components: Library (Lib), Windows Versions: Python 3.4
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: amaury.forgeotdarc, christian.heimes, draghuram, jaraco, loewis, martin.panter, mhammond, ocean-city
Priority: normal Keywords: patch

Created on 2008-01-08 17:12 by christian.heimes, last changed 2022-04-11 14:56 by admin.

Files
File name Uploaded Description Edit
trunk_winpath.patch christian.heimes, 2008-01-08 17:12
trunk_os_getshellfolders.patch christian.heimes, 2008-01-08 22:26 review
1763_knownfolders.patch christian.heimes, 2013-06-24 17:01 review
Messages (20)
msg59547 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2008-01-08 17:12
The new module "winpath" gives easy access to Windows shell folders like
my documents, my files, application data etc.
msg59549 - (view) Author: Raghuram Devarakonda (draghuram) (Python triager) Date: 2008-01-08 17:55
The current 'path' modules such as posixpath and ntpath have functions
that operate on a file path. But I see this module more as a way of
getting information related to one's profile. So the name 'winpath' may
not be a good choice.
msg59551 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2008-01-08 18:04
I'm not very good in naming things. I'm open to suggestions :)
msg59553 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2008-01-08 18:56
I believe Microsoft advises against looking at the registry to find
these things, and advocates the use of SHGetFolder instead:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/apcompat/apcompat/use_the_application_programming_interface_to_locate_special_folders.asp

As for naming things: I guess an object ShellFolders in ntpath might
work fine, with (computed) attributes Desktop, Documents, etc (according
to the FOLDERID_ symbolic constants of the API).

OTOH, this is entirely ad-hoc, as tons of other Windows API is *not*
directly exposed to Python, so it's questionable why this one
specifically deserves being supported.

The patch has no documentation.
msg59567 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2008-01-08 22:26
Here is a new patch which adds os.path.getshellfolders(). It uses
SHGetFolderPathW which is compatible with Windows 2000.

I've implemented the API because several of my project need the path to
my documents. I've a personal interested in the specific feature. It may
also be required for a new, user specific site-package directory. The
feature is currently being discussed on the python-dev list.
msg59584 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2008-01-09 09:05
> It uses SHGetFolderPathW which is compatible with Windows 2000.

Is Python supposed to still work on Windows NT 4?

http://svn.python.org/projects/python/trunk/README says that support
will be droppen in 2.6 for Win9x and WinME, but says nothing about NT4.

OTOH, the msdn library site removed many references to NT4 (see the doc
for CreateFile, for example). It could be wise to say that python 2.6 is
supported only on Windows 2000 and up.
msg59585 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2008-01-09 09:18
It was never explicitly discussed, however, I always assumed that NT4
support is not necessary anymore.

I would like to pose a policy that Python does not need to support
Windows releases which have left Microsoft's "extended support". For NT
4 WS, this was on 30.6.2004. For Windows 2000 Pro, this will be on
13.7.2010. Of course, *testing* the releases on Windows 2000 will become
difficult - I don't have access to Windows 2000 installations anymore.
msg59586 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2008-01-09 09:52
OK. We should also remove references to older versions on the website:
http://www.python.org/download/releases/2.5.1/ and the various READMEs.

For testing older platforms, we can still use virtual machines. I think
this is how Christian develops on Windows XP.
msg59599 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2008-01-09 14:00
Amaury Forgeot d'Arc wrote:
> For testing older platforms, we can still use virtual machines. I think
> this is how Christian develops on Windows XP.

Correct, I'm using a VMWare installation of Windows XP SP2 German and
DesktopBSD (FreeBSD variant) to test Python on Windows and BSD. Several
of the build bots seem to use a VMWare installation, too.

Christian
msg59617 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2008-01-09 18:44
> OK. We should also remove references to older versions on the website:
> http://www.python.org/download/releases/2.5.1/ and the various READMEs.

No. Python 2.5.1 *does* support Windows 95 (I have myself tested that).
Only 2.6 will drop support for 9x.
msg60076 - (view) Author: Mark Hammond (mhammond) * (Python committer) Date: 2008-01-18 00:01
I'm not sure why the approach of "load-em-all" is being taken. 
Interestingly, SHGetFolderPathW is listed as deprecated, so I doubt that
list will grow too much, but the implementation as specified prevents
the user from using other facilities available via the API (ie, what if
they *do* want it verified?  What if they want to specify
CSIDL_FLAG_CREATE?)

That said though, I don't object to the patch as it stands, and agree it
will meet the requirements of the majority of people who need a "known
path" on Windows.
msg60082 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2008-01-18 08:07
Mark Hammond wrote:
> I'm not sure why the approach of "load-em-all" is being taken. 
> Interestingly, SHGetFolderPathW is listed as deprecated, so I doubt that
> list will grow too much, but the implementation as specified prevents
> the user from using other facilities available via the API (ie, what if
> they *do* want it verified?  What if they want to specify
> CSIDL_FLAG_CREATE?)
> 
> That said though, I don't object to the patch as it stands, and agree it
> will meet the requirements of the majority of people who need a "known
> path" on Windows.

Indeed, the patch targets the most basic requirements. I wanted to
implement a simple and straight solution without implementing a complex
API or adding about 30 new constants to a module. Users with extend
needs should use your pywin32 package. I don't feel like rewriting your
package here. ;)
msg62242 - (view) Author: Hirokazu Yamamoto (ocean-city) * (Python committer) Date: 2008-02-10 02:12
Sorry for interruption. I'm a little doubtful this is really needed.
We can get "My Documents" path by following 5 lines of code.

import ctypes

dll = ctypes.windll.shell32
buf = ctypes.create_string_buffer(300)
dll.SHGetSpecialFolderPathA(None, buf, 0x0005, False)
print buf.value

And if this patch goes in, I'm using clipboard in my several python
scripts, is it also possible to add clipboard support?
(I implemented ocean/clipboard.py under PYTHONPATH and now using it
personally)

# And, well, r60696 blocks me from building python on VC6, if this change
# (WINVER = 0x500) is required for this issue only, I'm happy if this
# would be reverted but... I cannot claim it loudly. I'm using win2000,
# and latest free compiler doesn't support it :-(
msg62277 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2008-02-11 10:52
> I'm using win2000, and latest free compiler doesn't support it :-(
I hope it does. r60696 is only about supporting win2000 when compiled
with vs9.

Building with vc6 should be corrected. I filed issue2065.
msg110596 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2010-07-17 19:08
@Christian: have you any interest in keeping this open or can it be closed, gien that the last comment was 2 1/2 years ago?
msg116859 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2010-09-19 10:52
No reply to msg110596.
msg191760 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2013-06-24 13:16
Oh my, this patch is rather ancient. Is this feature still of interest? I'm happy to port it from 2.6 to 3.4.
msg191767 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013-06-24 14:28
See also PyXDG (http://freedesktop.org/wiki/Software/pyxdg/) and winpaths (http://ginstrom.com/code/winpaths.html).
msg191787 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2013-06-24 17:01
Here is a patch that returns the paths of all known SHGetKnownFolderPath() and SHGetFolderPath(). SHGetKnownFolderPath() is currently not available for Python 3.4 as Python 3.4 still uses Windows XP API but SHGetKnownFolderPath() requires Vista or newer.

http://msdn.microsoft.com/en-us/library/windows/desktop/bb776911%28v=vs.85%29.aspx
msg232979 - (view) Author: Jason R. Coombs (jaraco) * (Python committer) Date: 2014-12-20 19:17
+1 from me for supporting this functionality in Python natively.

I tried winpaths but it doesn't yet support Python 3. I've e-mailed the author so it might be considered for a future release.
History
Date User Action Args
2022-04-11 14:56:29adminsetgithub: 46103
2014-12-20 20:56:00martin.pantersetnosy: + martin.panter
2014-12-20 19:17:10jaracosetnosy: + jaraco
messages: + msg232979
2014-02-03 15:47:10BreamoreBoysetnosy: - BreamoreBoy
2013-11-17 14:46:29serhiy.storchakasetnosy: - serhiy.storchaka
2013-06-24 17:01:02christian.heimessetfiles: + 1763_knownfolders.patch

messages: + msg191787
title: Winpath module - easy access to Windows directories like My Documents -> Get path to shell/known folders on Windows
2013-06-24 14:28:24serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg191767
2013-06-24 13:16:00christian.heimessetstatus: languishing -> open

messages: + msg191760
versions: + Python 3.4, - Python 3.2
2010-09-24 03:13:56r.david.murraysetstatus: closed -> languishing
2010-09-19 10:52:13BreamoreBoysetstatus: open -> closed

messages: + msg116859
2010-08-09 04:21:08terry.reedysetversions: + Python 3.2, - Python 3.1, Python 2.7
2010-07-17 19:08:50BreamoreBoysetnosy: + BreamoreBoy
messages: + msg110596
2009-04-27 23:50:19ajaksu2setstage: patch review
versions: + Python 3.1, Python 2.7, - Python 2.6
2008-02-11 10:52:33amaury.forgeotdarcsetmessages: + msg62277
2008-02-10 02:12:42ocean-citysetnosy: + ocean-city
messages: + msg62242
2008-01-18 08:07:31christian.heimessetmessages: + msg60082
2008-01-18 00:01:01mhammondsetnosy: + mhammond
messages: + msg60076
2008-01-09 18:44:03loewissetmessages: + msg59617
2008-01-09 14:00:30christian.heimessetmessages: + msg59599
2008-01-09 09:52:24amaury.forgeotdarcsetmessages: + msg59586
2008-01-09 09:18:41loewissetmessages: + msg59585
2008-01-09 09:05:35amaury.forgeotdarcsetnosy: + amaury.forgeotdarc
messages: + msg59584
2008-01-08 22:26:46christian.heimessetfiles: + trunk_os_getshellfolders.patch
messages: + msg59567
2008-01-08 18:56:11loewissetnosy: + loewis
messages: + msg59553
2008-01-08 18:04:35christian.heimessetmessages: + msg59551
2008-01-08 17:55:59draghuramsetnosy: + draghuram
messages: + msg59549
2008-01-08 17:12:57christian.heimescreate