Skip to content
DevOps AI ToolKit
Newsletter
All prompts
AI for Bash & Python Automation Difficulty: Intermediate ClaudeChatGPT

Idempotent Bulk File Rename & Migrate Tool Prompt

Write a Python tool that safely renames or relocates large batches of files using a rule set, with mandatory dry-run, collision detection, atomic moves, and an undo manifest so a bad run is reversible.

Target user
Automation engineers performing bulk filesystem operations
Difficulty
Intermediate
Tools
Claude, ChatGPT

The prompt

You are a senior Python engineer who builds filesystem automation that is impossible to fire blindly. The default mode must be a preview; real changes require an explicit flag.

I will provide:
- The renaming/relocation rule (regex, prefix/suffix change, date-based foldering, slugify, etc.)
- The source tree and target layout, and whether moves cross filesystems
- Constraints: must existing files be overwritten, skipped, or is that an error?

Your job:

1. **Default to dry-run** — the tool plans the full set of (source → destination) operations and prints them; nothing mutates unless `--apply` is passed. State this loudly in the help text.
2. **Detect collisions before acting** — fail (or follow the configured policy) if two sources map to the same destination, or a destination already exists. Never silently clobber.
3. **Move atomically** — use `os.replace` for same-filesystem renames; for cross-filesystem, copy-to-temp then atomic rename, and only delete the source after the copy verifies.
4. **Be idempotent** — a file already at its target is a no-op, not an error, so re-running a partially-completed batch is safe.
5. **Write an undo manifest** — record every applied move to a JSON file and provide an `--undo <manifest>` mode that reverses them in order.
6. **Report clearly** — counts of planned/applied/skipped/conflicted, and use `pathlib` throughout.

Output: the full tool with `argparse`, the collision and undo logic, a dry-run transcript, and the matching undo transcript.
Newsletter

Free: the DevOps AI Incident-Triage Cheat Sheet

Subscribe and we’ll send you the one-page cheat sheet — plus weekly AI prompts, automation ideas, and tool reviews for infrastructure engineers. One email a week. No spam, unsubscribe anytime.

  • AI Incident-Triage Cheat Sheet (PDF)
  • Access to 2,104 DevOps AI prompts
  • One practical workflow email per week