← 返回
未分类

文件自动归档助手

Automatically organize and archive files based on customizable rules. Use this skill when the user needs to (1) organize messy directories, (2) archive files by type/date/pattern, (3) bulk-move or copy files to structured folders, or (4) set up automated file organization workflows. Supports pattern matching, date-based folders, structure preservation, and dry-run previews.
自动按文件类型、日期或自定义规则,对文件夹里的文件进行分类归档,支持一键整理杂乱目录、批量移动文件和清理空文件夹,帮你高效完成文件管理。
jm-jsjkxyjs02-wyt-162
未分类 community v1.0.0 1 版本 100000 Key: 无需
★ 1
Stars
📥 72
下载
💾 0
安装
1
版本
#latest

概述

File Archiver Skill

Automatically organize and archive files using rule-based Python scripts.

Quick Start

1. Create Default Configuration

Generate a starter configuration file with example rules:

python scripts/archive_files.py --create-config config.json

This creates config.json with example rules for PDFs, images, and old files.

2. Customize Configuration

Edit config.json to match your archiving needs:

{
  "rules": [
    {
      "name": "PDF Documents",
      "pattern": "*.pdf",
      "destination": "./archive/documents/pdf",
      "use_date_folder": false,
      "preserve_structure": false
    },
    {
      "name": "Images by Date",
      "pattern": "*.jpg",
      "destination": "./archive/images",
      "use_date_folder": true,
      "preserve_structure": false
    }
  ]
}

Rule Fields:

  • name: Human-readable rule name
  • pattern: File pattern to match (.pdf, .jpg, report, or for all files)
  • destination: Where to move/copy matched files
  • use_date_folder: Create YYYY-MM-DD subfolder in destination
  • preserve_structure: Keep original directory structure relative to source

3. Preview Archiving (Dry Run)

Test your rules without actually moving files:

python scripts/archive_files.py /path/to/source -c config.json --dry-run

4. Execute Archiving

Move files to archive:

python scripts/archive_files.py /path/to/source -c config.json

Copy files (keep originals):

python scripts/archive_files.py /path/to/source -c config.json -k

Configuration Examples

Example 1: Organize by File Type

{
  "rules": [
    {"name": "Documents", "pattern": "*.pdf", "destination": "./docs", "use_date_folder": false, "preserve_structure": false},
    {"name": "Images", "pattern": "*.jpg", "destination": "./images", "use_date_folder": false, "preserve_structure": false},
    {"name": "Videos", "pattern": "*.mp4", "destination": "./videos", "use_date_folder": true, "preserve_structure": false}
  ]
}

Example 2: Archive Old Files by Date

{
  "rules": [
    {
      "name": "Old Files Archive",
      "pattern": "*",
      "destination": "./archive",
      "use_date_folder": true,
      "preserve_structure": true
    }
  ]
}

Example 3: Project-Based Organization

{
  "rules": [
    {"name": "Source Code", "pattern": "*.py", "destination": "./project/src", "use_date_folder": false, "preserve_structure": true},
    {"name": "Documentation", "pattern": "*.md", "destination": "./project/docs", "use_date_folder": false, "preserve_structure": false},
    {"name": "Tests", "pattern": "test_*.py", "destination": "./project/tests", "use_date_folder": false, "preserve_structure": false}
  ]
}

Pattern Matching

The pattern field supports:

  • Extension match: *.pdf matches all PDF files
  • Wildcard match: report_* matches files starting with "report_"
  • Exact match: readme.txt matches exactly that file
  • Catch-all: * matches all files (use with caution)

Uses Python's fnmatch for wildcard matching.

Command-Line Options

python scripts/archive_files.py SOURCE [-c CONFIG] [OPTIONS]

Required:
  SOURCE              Source directory to scan

Options:
  -c, --config PATH   Configuration file path (JSON)
  -d, --dry-run       Simulate without moving/copying files
  -k, --keep-original Copy files instead of moving them
  --create-config PATH Create default configuration file

Workflow Integration

Use with OpenClaw

When user asks to organize files, archive old files, or clean up directories:

  1. Ask user for source directory and archiving preferences
  2. Generate appropriate config.json based on their needs
  3. Run dry-run first to show what will be archived
  4. Execute actual archiving after user confirmation

Example Conversation

User: "Help me organize my Downloads folder. I want to separate PDFs, images, and everything else."

Assistant:

  1. Creates config.json with rules for .pdf, .jpg/.png, and
  2. Runs dry-run to show preview
  3. After confirmation, executes archiving

Advanced Usage

Date-Based Folders

Set use_date_folder: true to organize files by archive date:

./archive/images/
├── 2024-01-15/
│   ├── photo1.jpg
│   └── photo2.jpg
└── 2024-01-16/
    └── photo3.jpg

Preserve Directory Structure

Set preserve_structure: true to maintain relative paths:

Source: /data/projects/alpha/report.pdf

Destination: ./archive/projects/alpha/report.pdf

Combining Rules

Files match the first rule that matches their pattern. Order rules from most specific to least specific.

Troubleshooting

"Config file not found"

  • Ensure -c config.json points to the correct path
  • Use absolute paths or ensure you're in the correct working directory

"Source directory not found"

  • Verify the source path exists
  • Use quotes for paths with spaces: "/path/to/source"

Files not matching expected rules

  • Check pattern syntax (use *.pdf not just .pdf)
  • Remember: only the first matching rule applies
  • Use --dry-run to see which rule matches each file

Technical Details

Script: scripts/archive_files.py

  • Pure Python, no external dependencies
  • Uses shutil for file operations
  • Handles Unicode filenames correctly
  • Cross-platform (Windows/Mac/Linux)

Return Value: JSON-like dictionary with archiving results

Safety:

  • Dry-run mode prevents accidental data loss
  • Copy mode (-k) preserves originals
  • Exceptions are caught and reported per-file

License

MIT License (default for user-created skills)

版本历史

共 1 个版本

  • v1.0.0 Initial release 当前
    2026-05-22 21:30 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

学术&职场文书全能定制工坊

user_7a275316
专为中国大学生与职场新人打造的全流程文书创作神器,零门槛搞定论文、竞赛申报、演讲稿、简历等各类文书。内置场景化引导、多版本对比、素材库与格式规范,支持分段生成与实时修改,告别“不会写、写不好、格式乱”的痛点,高效省心又专业。而且内置素材大幅
★ 1 📥 116

智能多媒体批量处理工具

user_7a275316
Complete multimedia batch processing tool skill in Chinese, located at C:\Users\20404\.claude\projects\multimedia-tool
★ 1 📥 63

AI营销创意内容生成助手

user_7a275316
这是一套由 AI 驱动的高级创意内容生成套件,可制作专业营销素材,包括社交海报、数据可视化图表、AI 生成文案以及完整的营销活动方案。 核心功能: • 支持 4 种卡片样式、7 种图表类型(柱状图 / 折线图 / 饼图 / 雷达图 / 散点
★ 0 📥 72