Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

select any folder as startfolder for browsing (win32gui,win32com, SHGetFolderLocation)

I want to start with a folder e.g. C:\test
instead of any of the predefined CSIDL_* folders. How can I achieve that?

    ''' 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
    '''
like image 270
ack Avatar asked Sep 20 '25 11:09

ack


1 Answers

You need to get a PIDL for the desired folder.

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

then pass that into SHBrowseForFolder

like image 81
Jeff R. Avatar answered Sep 23 '25 00:09

Jeff R.