You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何仅用ctypes通过SHOpenFolderAndSelectItems在资源管理器中选中文件?

在Python中实现资源管理器选中指定文件

基于pywin32的实现方式

借助pywin32库可以快速实现该功能,代码示例如下:

from win32com.shell import shell
def showFilesInExplorer(folder, files):
    folder_pidl = shell.SHILCreateFromPath(folder, 0)[0]
    files_pidl = [shell.SHILCreateFromPath(f, 0)[0] for f in files]
    shell.SHOpenFolderAndSelectItems(folder_pidl, files_pidl, 0)

无依赖的ctypes实现思路

如果希望避免依赖pywin32库,理论上可以仅通过ctypes直接调用Windows系统API来完成同样的功能,无需引入第三方库。

内容的提问来源于stack exchange,提问作者arenasys

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.09 17:27:02