[python-win32] Example code for SHOpenFolderAndSelectItems?
rupole at hotmail.com
Wed Sep 5 08:02:17 CEST 2012
Scott Nelson wrote:
> Would anyone happen to have some sample code of how to use
> SHOpenFolderAndSelectItems? I've been tinkering with it and haven't got
> anything to work yet. This is the closest I've got:
>>>> from win32com.shell import shell
>>>> shell.SHOpenFolderAndSelectItems((r'c:\junk', ), 1)
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> TypeError: Must be an array of IDLs
> The errors I've seen in my experiments mention "IDLs" and "ITEMIDLIST"
> objects. I've dug a bit through the pywin32 docs and MDSN and didn't have
> much luck understanding what the Python wrapper required and how to
> construct these object. I must admit I don't have much Win32 API
> programming experience.
> I'm using Active State's Python 22.214.171.124 on Vista and I installed the 32 bit
> version of pywin32, build 217.
> For reverence, here's some links:
> I submitted the feature request for SHOpenFolderAndSelectItems:
> The changeset that implements this function is here:
> And, here's the MSDN doc:
> Any nudges in the right direction would be helpful.
from win32com.shell import shell, shellcon
folder = win32api.GetTempPath()
desktop = shell.SHGetDesktopFolder()
shell_folder = desktop.BindToObject(folder_pidl, None, shell.IID_IShellFolder)
items = [item for item in shell_folder][:5]
## print (items)
shell.SHOpenFolderAndSelectItems(folder_pidl, items, 0)
More information about the python-win32