How do you get the exact path to “My Documents”?

后端 未结 1 1080
星月不相逢
星月不相逢 2021-02-07 17:35

In C++ it\'s not too hard to get the full pathname to the folder that the shell calls \"My Documents\" in Windows XP and Windows 7 and \"Documents\" in Vista; see Get path to My

相关标签:
1条回答
  • 2021-02-07 18:12

    You could use the ctypes module to get the "My Documents" directory:

    import ctypes
    from ctypes.wintypes import MAX_PATH
    
    dll = ctypes.windll.shell32
    buf = ctypes.create_unicode_buffer(MAX_PATH + 1)
    if dll.SHGetSpecialFolderPathW(None, buf, 0x0005, False):
        print(buf.value)
    else:
        print("Failure!")
    

    Source: http://bugs.python.org/issue1763#msg62242

    0 讨论(0)
提交回复
热议问题