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

后端 未结 1 1926
野趣味
野趣味 2021-02-07 17:17

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 17:54

    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)
提交回复
热议问题