Skill: dougchambes/legend-file-organizer (version 1.0.0)

--- name: file-organizer description: "File organization and batch operations for workspace management. Use when organizing files for: (1) Moving files to correct directories, (2) Batch renaming (patterns, numbering, dates), (3) Creating directory structures, (4) Organizing by type/extension, (5) Cleaning scattered files, (6) Project scaffolding, or (7) Restructuring project layouts." --- # File Organizer Manages file organization through safe, predictable batch operations. ## Core Workflows ### Directory Structure Create standard project layouts: ``` project/ ├── src/ - Source code ├── docs/ - Documentation ├── tests/ - Test files ├── assets/ - Images, fonts, media ├── scripts/ - Build scripts, utilities └── config/ - Configuration files ``` ### Moving Files - `mv <source> <dest>` - Single file - `find . -name "*.ext" -exec mv {} <dest>/ \;` - Batch by extension - Always confirm destination exists ### Batch Renaming **Patterns:** - Sequential numbering: `file_{001..100}.txt` - Date-based: `YYYY-MM-DD_description` - Type-based: Group by extension **Safe approach:** 1. `echo` commands first (dry run) 2. Review output 3. Remove `echo`, execute ### Organizing by Type Group files by extension into folders: ``` mkdir -p images docs code find . -name "*.png" -o -name "*.jpg" | xargs -I {} mv {} images/ find . -name "*.md" -o -name "*.txt" | xargs -I {} mv {} docs/ find . -name "*.py" -o -name "*.js" | xargs -I {} mv {} code/ ``` ### Finding Scattered Files ``` find . -type f -name "*.ext" # Find by extension find . -type f -mtime -7 # Modified in last 7 days find . -type f -size +100M # Large files ``` ### Dry Runs First Always preview batch operations: ``` echo "Would move these files:" find . -name "*.ext" # Review, then execute ``` ## Safety Rules 1. **Never delete** without explicit permission (use `trash` if available) 2. **Dry run first** - Always echo/preview batch operations 3. **Check destinations** - Confirm target directories exist 4. **Backup before restructure** - Snapshot before major moves 5. **Respect workspace boundaries** - Only touch ~/openclaw ## When to Read references/patterns.md Load when: - Complex rename patterns needed - Project structure templates required - Advanced find commands for filtering - Edge cases (symlinks, special characters)

path: references/patterns.md
content: # File Organization Patterns

## Directory Structure Templates

### Standard Project
```
project-name/
├── src/              # Source code
│   ├── components/
│   ├── utils/
│   └── index.js
├── tests/            # Test files
│   ├── unit/
│   └── integration/
├── docs/             # Documentation
│   └── api/
├── assets/           # Static files
│   ├── images/
│   ├── fonts/
│   └── styles/
├── scripts/          # Build/automation
├── config/           # Configuration
└── dist/             # Build output (gitignore)
```

### Documentation Site
```
docs/
├── guides/           # User guides
├── api/              # API reference
├── tutorials/        # Step-by-step
├── examples/         # Code samples
└── images/           # Documentation assets
```

### Research/Data
```
research/
├── data/             # Raw data
├── processed/        # Cleaned data
├── analysis/         # Scripts, notebooks
├── outputs/          # Charts, reports
└── literature/       # Papers, notes
```

## Batch Rename Patterns

### Sequential Numbering
```bash
# Add prefix with numbering
i=1; for f in *.txt; do mv "$f" "doc_$(printf "%03d" $i).$f"; ((i++)); done

# Rename with date
for f in *.md; do mv "$f" "$(date +%Y-%m-%d)_$f"; done
```

### Extension-Based Organization
```bash
# Group by type
mkdir -p images docs code
find . -maxdepth 1 -name "*.png" -o -name "*.jpg" -o -name "*.gif" | xargs -I {} mv {} images/
find . -maxdepth 1 -name "*.md" -o -name "*.txt" -o -name "*.pdf" | xargs -I {} mv {} docs/
find . -maxdepth 1 -name "*.py" -o -name "*.js" -o -name "*.ts" | xargs -I {} mv {} code/
```

### Date-Based Organization
```bash
# Organize by modification date
for f in *; do
  if [ -f "$f" ]; then
    date=$(stat -c %y "$f" | cut -d' ' -f1)
    mkdir -p "$date"
    mv "$f" "$date/"
  fi
done
```

## Find Commands

### By Extension
```bash
find . -type f -name "*.py"              # Python files
find . -type f -name "*.md"              # Markdown files
find . -type f \( -name "*.jpg" -o -name "*.png" \)  # Multiple extensions
```

### By Modification Time
```bash
find . -type f -mtime -7                 # Modified in last 7 days
find . -type f -mtime +30                # Modified over 30 days ago
find . -type f -mmin -60                 # Modified in last hour
```

### By Size
```bash
find . -type f -size +100M               # Files > 100MB
find . -type f -size -1K                 # Files < 1KB
find . -type f -size +10M -size -50M     # Files 10-50MB
```

### By Depth
```bash
find . -maxdepth 1 -type f               # Files in current dir only
find . -mindepth 2 -type f               # Files nested 2+ levels
```

## Project Scaffolding

### Create Structure
```bash
mkdir -p project-name/{src,tests,docs,assets,scripts,config}
cd project-name
touch README.md
touch src/index.js
touch tests/index.test.js
```

### Initialize Git
```bash
git init
cat > .gitignore << EOF
node_modules/
dist/
.env
*.log
.DS_Store
EOF
git add -A
git commit -m "chore: initialize project structure"
```

### Copy Template
```bash
# From template directory
cp -r /path/to/template/* project-name/
# Or use tar for selective copy
tar -cf - --include='*.md' --include='*.js' /template | (cd project-name && tar -xf -)
```

## Safety Patterns

### Dry Run Pattern
```bash
# Always preview first
echo "Would move these files:"
find . -name "*.txt"
# Review output, then execute
find . -name "*.txt" -exec mv {} dest/ \;
```

### Backup Before Restructure
```bash
# Snapshot current state
tar -czf backup_$(date +%Y%m%d_%H%M%S).tar.gz target-directory/
# Or use git commit
git add -A
git commit -m "backup: pre-restructure snapshot"
```

### Safe Move with Error Handling
```bash
for f in *.txt; do
  if [ -f "$f" ]; then
    mv "$f" dest/ && echo "Moved: $f" || echo "Failed: $f"
  fi
done
```

### Avoid Overwriting
```bash
# Check if destination exists
for f in *.txt; do
  dest="target/$f"
  if [ -e "$dest" ]; then
    echo "Skip: $dest exists"
  else
    mv "$f" "$dest"
  fi
done
```

## Common Operations

### Flatten Nested Directories
```bash
# Move all files from subdirs to parent
find . -type f -exec mv {} . \;
# Remove empty dirs
find . -type d -empty -delete
```

### Remove Empty Files
```bash
find . -type f -empty -delete
```

### Find Duplicates (by name)
```bash
find . -type f -name "*.txt" | sort | uniq -d
```

### Organize Git Repo
```bash
# Move untracked files into proper structure
mkdir -p src docs tests
git status --short | grep '^??' | awk '{print $2}' | while read f; do
  case "$f" in
    *.md) mv "$f" docs/ ;;
    *.test.*) mv "$f" tests/ ;;
    *) mv "$f" src/ ;;
  esac
done
```

Security scan verdicts — ClawScan: clean | static analysis: clean | VirusTotal: clean | SkillSpector: clean (LOW)