Skip to main content

🧹 FileFlow CLI

智能文件整理器 — YAML 规则引擎驱动的 CLI 文件分类/移动/清理工具

PyPI version Python Version Downloads License: MIT Ruff GitHub Stars


🇬🇧 English · 🇨🇳 简体中文


✨ 一分钟上手

# 1. 安装
pip install fileflow-cli

# 2. 进入乱糟糟的下载目录
cd ~/Downloads

# 3. 生成配置文件
fileflow init

# 4. 预览整理效果(安全,不会动你的文件)
fileflow run

# 5. 确认后执行整理
fileflow run --force

搞定! 你的文件被自动分类到 Pictures/Documents/Code/Videos/Audio/ 等目录。


🎯 解决什么问题?

你的 Downloads 文件夹是不是像这样?

📁 Downloads/
├── IMG_2024.jpg
├── project_report.pdf
├── meeting_notes.docx
├── screenshot.png
├── vacation_photo.jpg
├── budget_2024.xlsx
├── app.py
├── style.css
├── video.mp4
├── song.mp3
├── archive.zip
├── another_doc.pdf
├── script.js
├── logo.svg
├── photo_from_2019.jpg
...

整理后 →

📁 Downloads/
├── 📁 Pictures/jpg/vacation_photo.jpg
│               png/screenshot.png
│               svg/logo.svg
├── 📁 Documents/pdf/project_report.pdf
│                 docx/meeting_notes.docx
│                 xlsx/budget_2024.xlsx
├── 📁 Code/py/app.py
│             css/style.css
│             js/script.js
├── 📁 Videos/mp4/video.mp4
├── 📁 Audio/mp3/song.mp3
├── 📁 Archives/zip/archive.zip

干净、有序、一目了然。


🚀 功能特性

特性 说明
🎯 YAML 规则引擎 声明式配置,想怎么分就怎么分
🔍 预览模式 先看效果再执行,安全无副作用
📂 6 种匹配方式 扩展名/通配符/正则/文件名包含/文件大小/组合 AND
📦 文件操作 移动/复制/删除,自动创建目录
冲突处理 跳过/重命名/覆盖,策略可选
支持撤销 fileflow undo 一键回退
📊 统计功能 fileflow stats 查看整理记录
🔌 可扩展 匹配器和操作都支持插件式注册
🎨 终端美化 Rich 进度条 + 彩色表格
🪶 轻量依赖 只需 typer + rich + pyyaml

📖 详细用法

命令一览

fileflow               # 🧹 欢迎面板 + 快速开始提示
fileflow run           # 🔍 预览并整理当前目录
fileflow run --force   # 📦 直接执行整理
fileflow init          # 🚀 生成默认 .fileflow.yaml
fileflow validate      # ✅ 验证配置文件 (简写: check)
fileflow list-rules    # 📋 查看规则列表 (简写: rules)
fileflow scan          # 🔍 扫描目录自动生成规则 (简写: sc)
fileflow stats         # 📊 查看统计信息
fileflow undo          # ⏪ 撤销最近操作
fileflow --help        # 📖 查看全部命令

常用选项

选项 说明
--config, -c 指定配置文件
--dry-run, -n 仅预览模式
--force, -f 跳过预览,直接执行
--yes, -y 跳过所有确认提示
--no-recursive 不扫描子目录
--no-progress 不显示进度条
--verbose, -v 详细输出
--version, -V 显示版本

示例

# 整理桌面
fileflow run ~/Desktop

# 使用自定义配置
fileflow run . --config ~/my-rules.yaml

# 不递归子目录
fileflow run --force --no-recursive

# 只预览,不确认
fileflow run --dry-run -y

# 自动扫描后缀并生成整理规则
fileflow scan

# 扫描时排除 .tmp 和 .log 文件
fileflow scan --exclude .tmp --exclude .log

# 只生成出现 5 次以上的后缀规则
fileflow scan --min-count 5

# 撤销最近 3 次操作
fileflow undo --steps 3

# 撤销所有操作
fileflow undo --all

📝 配置文件 (.fileflow.yaml)

version: "1.0"

settings:
  dry_run_by_default: true   # 默认预览模式
  on_conflict: "skip"        # skip | rename | overwrite
  create_target_dirs: true

rules:
  - name: "整理图片"
    description: "按扩展名分类图片"
    match:
      extensions: [".jpg", ".jpeg", ".png", ".gif", ".svg", ".bmp"]
    action: move
    target: "Pictures/{ext_no_dot}/{filename}"

  - name: "整理文档"
    match:
      extensions: [".pdf", ".doc", ".docx", ".xls", ".xlsx"]
      max_size_mb: 50         # 忽略超过 50MB 的文件
    action: move
    target: "Documents/{ext_no_dot}/{filename}"

  - name: "清理旧日志"
    match:
      extensions: [".log"]
      min_size_mb: 100        # 只处理超过 100MB 的日志
    action: delete
    enabled: false            # 默认禁用,需手动启用

📂 路径模板变量

变量 说明 示例值
{filename} 完整文件名 report.pdf
{name} 文件名(无扩展名) report
{ext_no_dot} 扩展名(无点,推荐目录用) pdf
{ext} 扩展名(含点) .pdf
{year} 4 位年份 2026
{month} 2 位月份 07
{day} 2 位日期 13

推荐使用 {ext_no_dot} 作为目录名,如 Documents/pdf/report.pdf,而不是 Documents/.pdf/report.pdf


🏗 项目架构

fileflow/
├── src/fileflow/
│   ├── cli.py        # CLI 命令 (Typer)
│   ├── config.py     # YAML 配置加载 & 验证
│   ├── engine.py     # 核心引擎 (扫描→匹配→执行)
│   ├── history.py    # 操作历史 & Undo
│   ├── rules.py      # 规则数据模型
│   ├── matchers.py   # 匹配器注册表 + 6 种内置匹配器
│   ├── actions.py    # 文件操作注册表 (move/copy/delete)
│   ├── templates.py  # 路径模板变量解析
│   └── report.py     # Rich 终端美化输出
├── tests/            # 76 项单元测试
├── .github/          # CI/CD 自动化
└── pyproject.toml    # 项目配置

🧩 设计亮点

匹配器注册表模式 — 新增匹配器只需注册,无需修改其他代码:

@register("my_matcher")
class MyMatcher(Matcher):
    def __call__(self, path: Path) -> bool:
        return path.suffix == ".xyz"

🧪 开发 & 测试

git clone https://github.com/Linger668/fileflow.git
cd fileflow
pip install -e ".[dev]"

# 运行测试
pytest

# 代码检查
ruff check src/
ruff format src/
mypy src/

🤝 贡献

欢迎提交 IssuePR

新手友好 👉 查看 good first issues


📄 许可证

MIT © 2026 Yuluo


如果 FileFlow 帮到了你,请给它 ⭐ 支持一下! 🌟

GitHub Stars

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fileflow_cli-0.4.0.tar.gz (37.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fileflow_cli-0.4.0-py3-none-any.whl (30.0 kB view details)

Uploaded Python 3

File details

Details for the file fileflow_cli-0.4.0.tar.gz.

File metadata

  • Download URL: fileflow_cli-0.4.0.tar.gz
  • Upload date:
  • Size: 37.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for fileflow_cli-0.4.0.tar.gz
Algorithm Hash digest
SHA256 5591ff4c71014c69b2d74b595ca6ee461842615d6aab72be9f6d662a442ee8a9
MD5 1c87ed09aeb368f7c0599ee81a11e043
BLAKE2b-256 05c4ede1913026fe00548acc8c0e6a00177f24983a668d4466e4b71fc490c0aa

See more details on using hashes here.

File details

Details for the file fileflow_cli-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: fileflow_cli-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 30.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for fileflow_cli-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c8f13248d4ffe04ec9940830ca8a7cd614a8f9f53b76bbd6e7153a386e09613e
MD5 564b930ddba90bbb27971c812ec2716c
BLAKE2b-256 d59b030493cea4136b98617cdc131aa6601c3775ea52908675d4cf325953d32a

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.4.0 This release

2 files

0.3.1

2 files

0.3.0

2 files

0.2.1

2 files

0.2.0

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page