如何通过python从windows缓存中获取文件缩略图?

2024-10-04 03:25:51 发布

您现在位置:Python中文网/ 问答频道 /正文

目标是在尽可能短的时间内从windows上的选定文件夹中获取文件缩略图

Imagemagick和其他工具每次都会打开文件,因此它们可能不是最有效的。Windows中的内置机制有可能将缩略图放在缓存中,这在理论上可以大大提高速度

How to get thumbnail of file using the Windows API?answer)开始,道路变得清晰,但存在很多问题:

  • ^在以下位置找不到{a3}和IThumbnailCache
    1. ctypes.windell.shell32(只有函数,似乎没有简单的方法获得接口)
    2. win32com.shell.shell(PyWin32)
  • IID_IThumbnailProvider和{a6}到{a7}和IID:
    1. 在win32com.shell.shell中找不到该IID,因此它们是手动提供的

    2. IThumbnailProviderIShellItem::BindToHandler method:已修复,但现在错误如下所示:

      # str(shell.IID_IShellItem) == '{43826D1E-E718-42EE-BC55-A1E261C37BFE}'
      # str(shell.BHID_ThumbnailHandler) == '{7B2E650A-8E20-4F4A-B09E-6597AFC72FB0}'
      
      item = shell.SHCreateItemFromParsingName(r'd:\some.png', None, str(shell.IID_IShellItem))  # str() is works
      IID_IThumbnailProvider = '{e357fccd-a995-4576-b01f-234630154e96}'
      provider = item.BindToHandler(None, shell.BHID_ThumbnailHandler, IID_IThumbnailProvider)  # error
      
      > TypeError: 'There is no interface object registered that supports this IID'
      
    3. IShellItemImageFactory:怀疑IID的用法有误,但从下面的answer来看,它应该可以工作:

      IID_IShellItemImageFactory = '{bcc18b79-ba16-442f-80c4-8a59c30c463b}'
      item = shell.SHCreateItemFromParsingName(r'd:\some.png', None, IID_IShellItemImageFactory)  # error
      
      > TypeError: 'There is no interface object registered that supports this IID'
      

在不学习整个winapi的情况下,了解如何在所有这些环境中游泳将是非常棒的

提前谢谢

Windows 10(20H2)、Python 3.9.5、PyWin32 301


更新:找到关于PyWin32(pythoncom.CoCreateInstance can't create IZoneIdentifier; the interface is missing from registry too despite being documented in MSDN)的答案。简而言之,这些接口没有实现。审核人:

> import pythoncom
> pythoncom.InterfaceNames

所以。。还有两个问题。有没有不使用PyWin32就可以获得缩略图的选项?例如,通过ctypes。怎么做


Tags: 文件noneiswindowsshelliteminterfacepywin32