读取本地文本文件,自动检测编码(优先 GBK,失败则尝试 UTF-8)。
需要 Python 环境(Python 3.8+)
方式 1:Miniconda(推荐)
# 下载安装:https://docs.conda.io/en/latest/miniconda.html
方式 2:Python 官方安装包
# 下载:https://www.python.org/downloads/
# ⚠️ 安装时勾选 "Add Python to PATH"
方式 3:winget 安装(Windows)
winget install Python.Python.3.11
| 文件类型 | 依赖库 | 安装方式 |
|---|---|---|
| ---------- | -------- | ---------- |
.docx | python-docx | 首次读取时自动安装 |
.pdf | pypdf | 首次读取时自动安装 |
无需手动安装这些库,首次使用时会自动安装。
node {skillDir}/scripts/read-file.js "文件路径.txt"
| 格式 | 说明 |
|---|---|
| ------ | ------ |
| .txt | 纯文本文件(GBK/UTF-8 自动检测) |
| .md | Markdown 文件 |
| .csv | CSV 文件(GBK 编码常见于 Excel 导出) |
| .log | 日志文件 |
| .docx | Word 文档(自动安装 python-docx) |
| PDF 文档(自动安装 pypdf,仅支持文字版 PDF) | |
| .json | JSON 文件 |
| .xml | XML 文件 |
| .ini / .cfg | 配置文件 |
# 读取普通文本文件
node {skillDir}/scripts/read-file.js "D:\文档\笔记.txt"
# 读取 CSV 文件
node {skillDir}/scripts/read-file.js "D:\数据\报表.csv"
# 读取 Word 文档
node {skillDir}/scripts/read-file.js "D:\华为项目\病历.docx"
| Select-Object),直接输出即可共 1 个版本