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

问题描述 投票:0回答:1

我想从一个文件夹开始,例如C:\ test \而不是任何预定义的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
    '''
python-3.x win32com win32gui
1个回答
1
投票

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

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

然后将其传递给SHBrowseForFolder

© www.soinside.com 2019 - 2024. All rights reserved.