智能文件整理工具,自动分类下载文件
Project description
📂 Smart File Organizer
一个智能文件整理工具,自动将 ~/Downloads 中的文件按类型分类。
🚀 功能特点
- ✅ 自动分类:图片、文档、视频、音频、压缩包、代码
- ✅ 同名文件处理:自动添加时间戳避免覆盖
- ✅ 模拟运行模式:安全测试,不移动实际文件
- ✅ 详细日志记录:所有操作记录在
/tmp/smart_file_organizer.log - ✅ 定时任务支持:可配置为每天自动运行
- ✅ 跳过隐藏文件和目录:自动忽略
.开头的文件和子目录 - ✅ 统计报告:显示整理结果和分类统计
📦 安装
从 PyPI 安装(推荐)
pip install smart-file-organizer
从源码安装
git clone https://github.com/yourusername/smart-file-organizer.git
cd smart-file-organizer
pip install -e .
开发模式安装
git clone https://github.com/yourusername/smart-file-organizer.git
cd smart-file-organizer
pip install -e ".[dev]"
🎯 使用方法
基本使用
整理默认目录(~/Downloads):
organize-files
指定源目录
organize-files --source ~/Documents
指定目标目录
organize-files --source ~/Downloads --target ~/Organized
试运行模式(推荐首次使用)
organize-files --dry-run
设置日志级别
organize-files --log-level DEBUG
完整示例
# 试运行,查看将要执行的操作
organize-files --source ~/Downloads --dry-run
# 实际执行整理
organize-files --source ~/Downloads
# 整理到指定目录
organize-files --source ~/Downloads --target ~/OrganizedFiles
📋 支持的文件类型
图片 (images)
jpg, jpeg, png, gif, bmp, svg, webp, ico, tiff, tif, heic, heif
文档 (documents)
pdf, doc, docx, xls, xlsx, ppt, pptx, txt, rtf, odt, ods, odp, pages, numbers, key
视频 (videos)
mp4, avi, mov, wmv, flv, mkv, webm, m4v, mpg, mpeg, 3gp, 3g2
音频 (audio)
mp3, wav, flac, aac, ogg, wma, m4a, opus, aiff, au
压缩包 (archives)
zip, rar, 7z, tar, gz, bz2, xz, tar.gz, tar.bz2, tar.xz, dmg, iso
代码 (code)
py, js, html, css, java, cpp, c, h, hpp, cs, php, rb, go, rs, swift, kt, ts, tsx, jsx, vue, json, xml, yaml, yml, sh, bash, zsh, ps1, bat, cmd, sql, md, markdown
📊 输出示例
============================================================
整理完成!
============================================================
总文件数: 10
已整理: 9
已跳过: 1
错误数: 0
按类别统计:
images : 2
documents : 2
videos : 1
audio : 1
archives : 1
code : 2
============================================================
⚙️ 配置
日志文件
日志文件默认保存在 /tmp/smart_file_organizer.log,包含所有操作的详细记录。
定时任务(macOS)
可以使用 launchd 配置定时任务。示例配置文件位于 launchd/com.smartfileorganizer.plist。
编辑配置文件:
# 编辑定时任务配置
nano launchd/com.smartfileorganizer.plist
# 加载定时任务
launchctl load ~/Library/LaunchAgents/com.smartfileorganizer.plist
# 立即运行一次
launchctl start com.smartfileorganizer
🧪 开发
运行测试
# 运行所有测试
python -m unittest tests.test_main -v
# 或使用 pytest
pytest tests/ -v
项目结构
SmartFileOrganizer/
├── src/
│ └── smart_file_organizer/
│ ├── __init__.py
│ ├── main.py # 主程序入口
│ └── utils.py # 工具函数
├── tests/
│ └── test_main.py # 单元测试
├── README.md
├── setup.py # 安装配置
├── pyproject.toml # 现代 Python 项目配置
├── MANIFEST.in # 包含文件清单
├── LICENSE # MIT 许可证
└── requirements.txt # 依赖列表
代码质量
# 代码格式化
black src/ tests/
# 代码检查
flake8 src/ tests/
# 类型检查
mypy src/
📝 命令行选项
| 选项 | 说明 | 默认值 |
|---|---|---|
--source |
源目录路径 | ~/Downloads |
--target |
目标目录路径(可选) | 源目录 |
--dry-run |
模拟运行模式,不实际移动文件 | False |
--log-level |
日志级别(DEBUG/INFO/WARNING/ERROR) | INFO |
-h, --help |
显示帮助信息 | - |
🔍 工作原理
- 扫描源目录:遍历指定目录中的所有文件
- 文件分类:根据文件扩展名识别文件类型
- 创建分类目录:在目标目录中创建对应的分类文件夹
- 移动文件:将文件移动到对应的分类目录
- 处理冲突:如果目标位置已存在同名文件,自动添加时间戳
- 生成报告:显示整理统计和结果
⚠️ 注意事项
- 工具会移动文件,而不是复制,请确保重要文件已备份
- 首次使用建议使用
--dry-run模式测试 - 隐藏文件(以
.开头)和子目录会被自动跳过 - 无法分类的文件会保留在原目录
🐛 问题反馈
如果遇到问题或有建议,请在 GitHub Issues 中提交。
📄 许可证
本项目采用 MIT 许可证。
🙏 致谢
感谢所有贡献者和使用者的支持!
Made with ❤️ for better file organization
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file smartfileorganizer_lin-0.1.0.tar.gz.
File metadata
- Download URL: smartfileorganizer_lin-0.1.0.tar.gz
- Upload date:
- Size: 16.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b942fe1f7d24871647dc668f64a305fbc8ad2303d7155659c391cb6071f6d67d
|
|
| MD5 |
ef73267584059a47ca6460124c8d8c37
|
|
| BLAKE2b-256 |
2bc18f156f2bd1d47e82141b152744005e6be850e44cdc1fb355b8fd47475e80
|
File details
Details for the file smartfileorganizer_lin-0.1.0-py3-none-any.whl.
File metadata
- Download URL: smartfileorganizer_lin-0.1.0-py3-none-any.whl
- Upload date:
- Size: 11.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
de3a1f7a3d5e4bc24ece170ddc7cbc2f48b744dfb66b85910943c956f7874c88
|
|
| MD5 |
faabb48698eee7d2d9c3dbf33200ca89
|
|
| BLAKE2b-256 |
460ca83316d1ccb4cb87fa51197d47c8e03ddbcb2c8cfdacb4be5532634fdf8b
|