Level 1 / Project 13 - Batch Rename Simulator¶
Home: README
Learn Your Way¶
| Read | Build | Watch | Test | Review | Visualize | Try |
|---|---|---|---|---|---|---|
| Concept | This project | — | Quiz | Flashcards | — | Browser |
Estimated time: 35 minutes
Focus¶
- safe rename planning without destructive changes
Why this project exists¶
Plan file renames without actually moving anything. Apply rules like lowercase, strip-numbers, or add-prefix, detect naming conflicts, and preview a before/after mapping. You will learn safe simulation before destructive operations.
Run (copy/paste)¶
Use <repo-root> as the folder containing this repository's README.md.
cd <repo-root>/projects/level-1/13-batch-rename-simulator
python project.py --input data/sample_input.txt --rule lower
pytest -q
Expected terminal output¶
=== Batch Rename Plan (rule: lower) ===
001_Project Report.docx => 001_project report.docx
002_Meeting Notes.txt => 002_meeting notes.txt
003_Budget Spreadsheet.xlsx => 003_budget spreadsheet.xlsx
3 renames planned, 0 conflicts
8 passed
Expected artifacts¶
data/output.json- Passing tests
- Updated
notes.md
Checkpoint: Baseline code runs and all tests pass. Commit your work before continuing.
Alter it (required) — Extension¶
- Add a new rule:
add_datethat prepends today's date asYYYY-MM-DD_to the filename. - Add a
--dry-runflag that prints the plan but does not write the output file. - Re-run script and tests.
Break it (required) — Core¶
- Add two files that would rename to the same target (e.g.
A.TXTanda.txtwith thelowerrule) -- doesdetect_conflicts()catch it? - Add an empty filename (blank line) -- does
simulate_rename()raiseValueError? - Use an unknown rule name like
--rule banana-- does argparse reject it or does the code crash?
Fix it (required) — Core¶
- Ensure
detect_conflicts()identifies all files that would collide after renaming. - Handle blank lines in the input by skipping them in
simulate_batch(). - Add a test for the conflict-detection case.
Checkpoint: All modifications done, tests still pass. Good time to review your changes.
Explain it (teach-back)¶
- Why is this a "simulator" and not an actual renamer? What safety benefit does simulation provide?
- Why does
RULESstore functions as dict values instead of using if/elif? - What does
re.sub(r"^\d+[\-_ ]*", "", stem)do inapply_rule_strip_numbers()? - Where would batch rename simulation appear in real software (file managers, migration scripts, DevOps tools)?
Mastery check¶
You can move on when you can: - run baseline without docs, - explain one core function line-by-line, - break and recover in one session, - keep tests passing after your change.
Related Concepts¶
| ← Prev | Home | Next → |
|---|---|---|