---
name: desktop-cleanup
description: "Organize files on the desktop or any directory by categorizing into folders."
whenToUse: "User asks to organize/clean their desktop"
---

# Skill: Desktop Cleanup & Organization

## Description
Organize files on the user's desktop or any directory by categorizing files into folders based on type, topic, or date. Handles deduplication and creates a clean folder structure.

## When to Use
- User asks to organize/clean their desktop
- User asks to sort files in a directory
- User says "整理一下桌面" or "帮我分类文件"

## Steps

### 1. Survey Current State
```python
import os

path = os.path.expanduser('~/Desktop')
entries = os.listdir(path)
# Categorize: files vs directories, by extension
```

### 2. Classification Rules

| Category | Extensions / Patterns | Folder Name |
|----------|----------------------|-------------|
| Documents | .pdf, .docx, .doc, .txt, .md | 工作文档 |
| Spreadsheets | .xlsx, .xls, .csv | 数据表格 |
| Presentations | .pptx, .ppt | 演示文稿 |
| Images | .png, .jpg, .jpeg, .gif, .bmp, .svg | 图片 |
| Code | .py, .js, .ts, .html, .css, .json | 代码文件 |
| Apps | .lnk, .exe | [Categorize by app type] |
| Archives | .zip, .rar, .7z, .tar.gz | 压缩包 |
| Videos | .mp4, .avi, .mkv, .mov | 视频 |
| Investment/Finance | *Gold*, *Fund*, *Stock*, 黄金*, 基金* | 投资分析 |

### 3. Smart Categorization
Don't just sort by extension — also check content/filename patterns:
- Financial reports → 投资分析
- PM/work reports → 工作文档
- Screenshots → 图片 or Misc Files
- App shortcuts → Group by function (Browsers, Development, etc.)

### 4. Move Files Safely
```python
import shutil

def safe_move(src, dst_dir, filename):
    os.makedirs(dst_dir, exist_ok=True)
    dst = os.path.join(dst_dir, filename)
    if os.path.exists(dst):
        # Add number suffix to avoid overwrite
        base, ext = os.path.splitext(filename)
        i = 1
        while os.path.exists(dst):
            dst = os.path.join(dst_dir, f"{base}_{i}{ext}")
            i += 1
    shutil.move(src, dst)
```

### 5. Respect Existing Structure
- Don't move files that are already in organized folders
- Don't touch system files (desktop.ini, etc.)
- Preserve existing folder categorization
- Ask before deleting duplicates

### 6. Report Results
After organizing, list:
- How many files were moved
- What folders were created
- What the desktop looks like now

## Important Notes
- **Never delete files without asking** — only move
- Skip `desktop.ini` and hidden files
- Check for duplicate shortcuts before removing
- Preserve existing folder structure — enhance, don't replace
