Visitar URL original
Get path to shell/known folders on Windows · Issue #46103 · python/cpython · GitHub
The Wayback Machine - https://web.archive.org/web/20241214190353/https://github.com/python/cpython/issues/46103
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get path to shell/known folders on Windows #46103

Open
tiran opened this issue Jan 8, 2008 · 23 comments
Open

Get path to shell/known folders on Windows #46103

tiran opened this issue Jan 8, 2008 · 23 comments
Labels
OS-windows stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@tiran
Copy link
Member

tiran commented Jan 8, 2008

BPO 1763
Nosy @loewis, @mhammond, @amauryfa, @jaraco, @tiran, @vadmium
Files
  • trunk_winpath.patch
  • trunk_os_getshellfolders.patch
  • 1763_knownfolders.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2008-01-08.17:12:57.575>
    labels = ['type-feature', 'library', 'OS-windows']
    title = 'Get path to shell/known folders on Windows'
    updated_at = <Date 2014-12-20.20:56:00.552>
    user = 'https://github.com/tiran'

    bugs.python.org fields:

    activity = <Date 2014-12-20.20:56:00.552>
    actor = 'martin.panter'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)', 'Windows']
    creation = <Date 2008-01-08.17:12:57.575>
    creator = 'christian.heimes'
    dependencies = []
    files = ['9106', '9111', '30689']
    hgrepos = []
    issue_num = 1763
    keywords = ['patch']
    message_count = 20.0
    messages = ['59547', '59549', '59551', '59553', '59567', '59584', '59585', '59586', '59599', '59617', '60076', '60082', '62242', '62277', '110596', '116859', '191760', '191767', '191787', '232979']
    nosy_count = 8.0
    nosy_names = ['loewis', 'mhammond', 'amaury.forgeotdarc', 'jaraco', 'ocean-city', 'draghuram', 'christian.heimes', 'martin.panter']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue1763'
    versions = ['Python 3.4']

    @tiran
    Copy link
    Member Author

    tiran commented Jan 8, 2008

    The new module "winpath" gives easy access to Windows shell folders like
    my documents, my files, application data etc.

    @tiran tiran added stdlib Python modules in the Lib dir OS-windows type-feature A feature request or enhancement labels Jan 8, 2008
    @draghuram
    Copy link
    Mannequin

    draghuram mannequin commented Jan 8, 2008

    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.

    @tiran
    Copy link
    Member Author

    tiran commented Jan 8, 2008

    I'm not very good in naming things. I'm open to suggestions :)

    @loewis
    Copy link
    Mannequin

    loewis mannequin commented Jan 8, 2008

    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.

    @tiran
    Copy link
    Member Author

    tiran commented Jan 8, 2008

    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.

    @amauryfa
    Copy link
    Member

    amauryfa commented Jan 9, 2008

    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.

    @loewis
    Copy link
    Mannequin

    loewis mannequin commented Jan 9, 2008

    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.

    @amauryfa
    Copy link
    Member

    amauryfa commented Jan 9, 2008

    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.

    @tiran
    Copy link
    Member Author

    tiran commented Jan 9, 2008

    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

    @loewis
    Copy link
    Mannequin

    loewis mannequin commented Jan 9, 2008

    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.

    @mhammond
    Copy link
    Contributor

    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.

    @tiran
    Copy link
    Member Author

    tiran commented Jan 18, 2008

    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. ;)

    @ocean-city
    Copy link
    Mannequin

    ocean-city mannequin commented Feb 10, 2008

    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 :-(

    @amauryfa
    Copy link
    Member

    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 bpo-2065.

    @BreamoreBoy
    Copy link
    Mannequin

    BreamoreBoy mannequin commented Jul 17, 2010

    @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?

    @BreamoreBoy
    Copy link
    Mannequin

    BreamoreBoy mannequin commented Sep 19, 2010

    No reply to msg110596.

    @BreamoreBoy BreamoreBoy mannequin closed this as completed Sep 19, 2010
    @bitdancer bitdancer reopened this Sep 24, 2010
    @bitdancer bitdancer added the stale Stale PR or inactive for long period of time. label Sep 24, 2010
    @tiran
    Copy link
    Member Author

    tiran commented Jun 24, 2013

    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.

    @tiran tiran removed the stale Stale PR or inactive for long period of time. label Jun 24, 2013
    @serhiy-storchaka
    Copy link
    Member

    @tiran
    Copy link
    Member Author

    tiran commented Jun 24, 2013

    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

    @tiran tiran changed the title Winpath module - easy access to Windows directories like My Documents Get path to shell/known folders on Windows Jun 24, 2013
    @jaraco
    Copy link
    Member

    jaraco commented Dec 20, 2014

    +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.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    @erlend-aasland
    Copy link
    Contributor

    Is this something you still want to champion, Jason?

    @jaraco
    Copy link
    Member

    jaraco commented May 20, 2022

    I'm +0 at this point. I understand that appdirs is meeting this need now.

    @erlend-aasland
    Copy link
    Contributor

    Sounds like this is a candidate for the pending (close) label.

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    OS-windows stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    7 participants