如何找到“我的文档”的确切路径?

2024-05-19 01:13:06 发布

您现在位置:Python中文网/ 问答频道 /正文

C++中,在Windows XP和WindowsXP和Vista中的“文档”中调用shell“我的文档”的文件夹并不难,参见Get path to My Documents

在Python中有一个简单的方法来实现这一点吗?


Tags: topath方法文档文件夹getmywindows
1条回答
网友
1楼 · 发布于 2024-05-19 01:13:06

您可以使用ctypes模块获取“我的文档”目录:

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!")

来源:http://bugs.python.org/issue1763#msg62242

相关问题 更多 >

    热门问题