Python 选择任何文件夹作为开始文件夹进行浏览(win32gui、win32com、SHGetFolderLocation)
我想从一个文件夹开始,例如C:\testPython 选择任何文件夹作为开始文件夹进行浏览(win32gui、win32com、SHGetFolderLocation),python,directory,win32com,win32gui,Python,Directory,Win32com,Win32gui,我想从一个文件夹开始,例如C:\test 而不是任何预定义的CSIDL\uuz*文件夹。 我怎样才能做到这一点 ''' python 3.6.2 ''' import os import win32gui from win32com.shell import shell, shellcon myfolder_pidl = shell.SHGetFolderLocation (0, shellcon.CSIDL_DESKTOP, 0, 0) p
而不是任何预定义的CSIDL\uuz*文件夹。 我怎样才能做到这一点
''' 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
您需要获得所需文件夹的PIDL
myfolder_pidl = shell.SHParseDisplayName(u"C:\test", 0)[0]
然后将其传递到文件夹
SHBrowseForFolder
我想知道为什么这被否决了。。。(34个月后)同意!这是非常不直观的,没有显示如何做到这一点,也没有其他明显的谷歌结果。你有我的+1。@Alex thx。。。杰夫的回答真的很有帮助…我想知道为什么这被否决了。。。(34个月后)同意!这是非常不直观的,没有显示如何做到这一点,也没有其他明显的谷歌结果。你有我的+1。@Alex thx。。。杰夫的回答真的很有帮助。。。