select 任何文件夹作为浏览的起始文件夹(win32gui、win32com、SHGetFolderLocation)
select any folder as startfolder for browsing (win32gui,win32com, SHGetFolderLocation)
我想从一个文件夹开始,例如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
我想从一个文件夹开始,例如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