如何通过Python查找与Windows文件关联的图标? [英] How to find via Python the icon associated with a Windows file?
问题描述
我正在开发Python脚本来在Windows上进行文件管理.本质上,我希望能够将文件移动到另一个位置,并在其位置创建Python脚本的快捷方式,该脚本将在打开重定位的文件之前执行中间步骤.我目前可以移动文件,创建有效的快捷方式并设置快捷方式图标图像.我剩下的唯一一件事就是弄清楚如何检测文件中显示的图标.
I'm developing a Python script to do file management on Windows. Essentially, I want to be able to move files to another location, and create in their place a shortcut to a Python script which will do intermediate steps before opening the relocated file. I can currently move files, create functioning shortcuts, and set the shortcut icon image. The only thing I have left is to figure out how to detect the icon which is displayed for the file.
-需要设置快捷方式的图标(指向".py"脚本)
-Need to set the icon for a shortcut (which points to a '.py' script)
-此图标应与我具有路径的任意文件类型,exe等匹配,
-This icon should match that of an arbitrary filetype, exe, etc, which I have the path to
-希望通过Python以编程方式完成. os.system()调用是可以接受的.不需要额外的模块(尽管我已经拥有win32com,winshell,pythoncom等),因此获得了额外的荣誉
-Hopefully done programmatically through Python. os.system() calls are acceptable. Extra credit is given for not requiring additional modules (though I already have win32com, winshell, pythoncom, etc)
预先感谢...
推荐答案
在 Windows注册表模块查找文件扩展名的类型.
File type information is found in the registry. You could look up the file extension's type with the windows registry module.
编辑:显示图标可通过shell32使用,如此处.尽管我不确定语法,但Python等效项似乎是ctypes.windll.shell32.ExtractIconA
.
Edit: It appears icons are available through shell32, as seen here. The Python equivalent seems to be ctypes.windll.shell32.ExtractIconA
, though I'm not sure about the syntax.
这篇关于如何通过Python查找与Windows文件关联的图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!