Skip to content

FileManager

聊天文件管理器,管理和操作所有聊天中的文件。

方法

open(filter_type=None)

打开文件管理面板。

  • filter_type str | None — 筛选类型:"全部" / "最近使用" / "文档" / "图片" / "视频" / "音乐" / "链接" / "其他"

search(keyword)

搜索聊天文件。

  • keyword str — 搜索关键词
  • 返回 List[ChatFile]

iter_chatfiles(count=None, speed=100)

逐条遍历聊天文件(通过滚动)。

  • count int | None — 最多获取条数
  • speed int — 滚动速度
  • Yields ChatFile

get_visible_chatfiles()

获取当前可见的文件列表。

  • 返回 List[ChatFile]

get_files(filter_type=None)

获取所有文件(指定类型筛选)。

  • 返回 List[ChatFile]

get_files_by_search(keyword)

搜索并获取文件。

  • 返回 List[ChatFile]

get_chatfile_by_id(file_id)

按 ID 获取指定文件。

  • 返回 ChatFile | None

save_file_as(chat_file, file_path)

另存文件到指定路径。

  • 返回 bool

download_to(chat_file, file_path)

下载文件到指定路径。

  • 返回 bool

download_file(chat_file, timeout=60)

下载文件(使用默认路径)。

  • 返回 bool

delete_file(chat_file)

删除文件。

  • 返回 bool

ChatFile 类

单个聊天文件。

属性

属性类型说明
file_idint文件 ID
file_namestr文件名
file_sizestr文件大小
file_typestr文件类型
senderstr发送者
chat_namestr来自哪个聊天
timestr时间
statusstr状态(已下载/未下载等)

方法

  • read(timeout=60) — 读取文件数据,返回 bytes
  • save_as(file_path) — 另存为
  • download_to(file_path) — 下载到指定路径
  • download() — 下载到默认路径
  • delete() — 删除文件
  • copy() — 复制文件路径
  • collect() — 收藏
  • switch_to_message() — 跳转到聊天中对应消息
  • switch_to_chat() — 跳转到聊天
  • edit() — 打开编辑

位置与可见性

is_in_list()

控件是否存在于文件列表的 UIA 树中。

  • 返回 bool

is_visible()

控件是否完全在文件列表的可视区域内。

  • 返回 bool

scroll_to_visible()

将文件项滚动到文件列表可视区域内。

  • 返回 bool

示例

python
from pywxauto import Weixin

wx = Weixin()

# 打开文件管理器并筛选文档
wx.file_manager.open(filter_type="文档")

# 搜索文件
files = wx.file_manager.search("报告")
for f in files:
    print(f"{f.file_name} - {f.file_size} - {f.sender}")

# 下载文件
files[0].download_to("C:/downloads/report.pdf")

# 遍历所有文件
for f in wx.file_manager.iter_chatfiles(count=100):
    print(f"{f.file_name} ({f.file_type})")