pywin32 programming error on Win7 with shell.SHGetDesktopFolder, desktop.BindToObject, desktop.GetDisplayNameOf

iMath redstone-cold at 163.com
Fri Nov 8 10:28:16 EST 2013


在 2013年11月8日星期五UTC+8下午5时47分43秒,Tim Golden写道:
> On 08/11/2013 03:30, iMath wrote:
> 
> > 
> 
> > When running the following code on WinXP , all is fine ,
> 
> > --------------------------------------------------------------
> 
> > from win32com.shell import shell
> 
> > 
> 
> > def launch_file_explorer(path, files):
> 
> > 
> 
> >     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 file not in name_to_item_mapping:
> 
> >             raise Exception('File: "{}" not found in "{}"'.format(file, path))
> 
> >         to_show.append(name_to_item_mapping[file])
> 
> >     shell.SHOpenFolderAndSelectItems(folder_pidl, to_show, 0)
> 
> > import os
> 
> > 
> 
> > 
> 
> > p=r'E:\aa'
> 
> > print(os.listdir(p))
> 
> > launch_file_explorer(p, os.listdir(p))
> 
> 
> 
> 
> 
> Did you mean to call .GetDisplayNameOf against the desktop folder? I
> 
> would have thought you wanted shell_folder.GetDisplayNameOf(item, 0).
> 
> 
> 
> TJG

I mainly want to use shell.SHOpenFolderAndSelectItems()



More information about the Python-list mailing list