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

孤街浪徒 提交于 2019-12-13 19:42:25

问题


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))

however ,when tested on Win7,I got the following error

['b1', 'b2', 't.txt']
Traceback (most recent call last):
  File "D:\g.py", line 21, in <module>
    launch_file_explorer(p, os.listdir(p))
  File "D:\g.py", line 13, in launch_file_explorer
    raise Exception('File: "{}" not found in "{}"'.format(file, path))
Exception: File: "t.txt" not found in "E:\aa"

I nearly have no experience on pywin32 programming ,the above code is googled,anyone can help me fix this error ?thanks in advance !

来源:https://stackoverflow.com/questions/19851113/pywin32-programming-error-on-win7-with-shell-shgetdesktopfolder-desktop-bindtoob

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!