代码之家  ›  专栏  ›  技术社区  ›  AcK

选择任意文件夹作为浏览的开始文件夹(win32gui、win32com、shgetfolderlocation)

  •  0
  • AcK  · 技术社区  · 6 年前

    我想从一个文件夹开始,例如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
        '''
    
    1 回复  |  直到 6 年前
        1
  •  1
  •   Jeff R.    6 年前

    您需要获得所需文件夹的PIDL。

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

    然后把那个传给 SHBrowseForFolder