gpt4 book ai didi

python - 选择任何文件夹作为浏览的起始文件夹(win32gui、win32com、SHGetFolderLocation)

转载 作者:行者123 更新时间:2023-12-05 04:05:46 25 4
gpt4 key购买 nike

我想从一个文件夹开始,例如C:\测试
而不是任何预定义的 CSIDL_* 文件夹。我怎样才能做到这一点?

    ''' python 3.6.2 '''

import os
import win32gui
from win32com.shell import shell, shellcon

myfolder_pidl = shell.SHGetFolderLocation (0, shellcon.CSIDL_DESKTOP, 0, 0)

pidl, display_name, image_list = shell.SHBrowseForFolder (
win32gui.GetDesktopWindow (),
myfolder_pidl,
"Select a file or folder",
0x00014050, #shellcon.BIF_BROWSEINCLUDEFILES and some more
None,
None
)

if (pidl, display_name, image_list) == (None, None, None):
print ('Nothing selected')
else:
my_path = shell.SHGetPathFromIDList (pidl)

file_to_process = my_path.decode()

''' continue processing file_to_process
'''

最佳答案

您需要为所需文件夹获取 PIDL。

myfolder_pidl = shell.SHParseDisplayName(u"C:\test", 0)[0]

然后将其传递到 SHBrowseForFolder

关于python - 选择任何文件夹作为浏览的起始文件夹(win32gui、win32com、SHGetFolderLocation),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50796382/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com