[python-win32] Example code for SHOpenFolderAndSelectItems?

Scott Nelson sirgnip at gmail.com
Thu Sep 6 14:05:48 CEST 2012


Roger,

Thanks much for the example code (and the implementation of the feature in
the first place!). It got me running.  For posterity, I copied in my
function below that wraps up your sample code in a function. Thanks again!

-Scott

from win32com.shell import shell, shellcon

def launch_file_explorer(path, files):
    '''Given a absolute base path and names of its children (no path), open
up one File Explorer window with all the child files selected'''
    folder_pidl = shell.SHILCreateFromPath(path,0)[0]
    desktop = shell.SHGetDesktopFolder()
    shell_folder = desktop.BindToObject(folder_pidl, None,
shell.IID_IShellFolder)
    name_to_item_mapping = dict([(desktop.GetDisplayNameOf(item, 0), item)
for item in shell_folder])
    to_show = []
    for file in files:
        if not name_to_item_mapping.has_key(file):
            raise Exception('File: "%s" not found in "%s"' % (file, path))
        to_show.append(name_to_item_mapping[file])
    shell.SHOpenFolderAndSelectItems(folder_pidl, to_show, 0)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20120906/e1c97c71/attachment.html>


More information about the python-win32 mailing list