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.
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Related prompts
-
Bash Dry-Run Mode Pattern Prompt
Add a first-class `--dry-run` mode to a Bash automation script so every mutating action is previewed instead of executed — with a single `run()` wrapper, clear PLAN output, and no accidental side effects.
-
Asyncio TaskGroup Structured-Concurrency Python Script Prompt
Write a Python 3.11+ automation script that fans work out with asyncio.TaskGroup so failures cancel siblings cleanly, errors aggregate into an ExceptionGroup, and no task is ever silently orphaned.
-
Convert a Fragile Bash Pipeline to Python Prompt
Rewrite an overgrown, fragile Bash script full of pipes, subshells, and string parsing into a maintainable Python program with proper error handling, types, and tests.
-
Idempotent systemd-Timer Maintenance Job Prompt
Write a safe, idempotent maintenance job (script plus systemd service and timer units) that can run on a schedule, survive overlaps and missed runs, and never corrupt state when run twice.
More Bash & Python Automation prompts & error guides
Browse every Bash & Python Automation prompt and troubleshooting guide in one place.
Reading prompts? Get all 500 in one free PDF
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.