Level 4 / Project 05 - Path Safe File Mover¶
Home: README
Learn Your Way¶
| Read | Build | Watch | Test | Review | Visualize | Try |
|---|---|---|---|---|---|---|
| — | This project | — | — | Flashcards | — | Browser |
Estimated time: 55 minutes
Focus¶
- safe move plans and collision prevention
Why this project exists¶
This project gives you level-appropriate practice in a realistic operations context. Goal: run the baseline, alter behavior, break one assumption, recover safely, and explain the fix.
Run (copy/paste)¶
Use <repo-root> as the folder containing this repository's README.md.
cd <repo-root>/projects/level-4/05-path-safe-file-mover
# Create sample source files first:
mkdir -p data/source && echo "hello" > data/source/report.csv && echo "world" > data/source/data.txt
python project.py --source data/source --dest data/dest --output data/move_log.json
pytest -q
Expected terminal output¶
Expected artifacts¶
data/dest/— moved filesdata/move_log.json— detailed move log with timestamps- Passing tests
- Updated
notes.md
Checkpoint: Baseline code runs and all tests pass. Commit your work before continuing.
Alter it (required) — Extension¶
- Add a
--patternflag to only move files matching a glob (e.g.,*.csv). - Add a
--backupflag that copies instead of moves, preserving the originals. - Re-run script and tests — add a test for the glob filter.
Break it (required) — Core¶
- Try to move files from a non-existent source directory — observe the error.
- Create a situation where a move fails mid-batch (e.g., read-only destination) and verify rollback.
- Run the same move twice and confirm collision handling works.
Fix it (required) — Core¶
- Add a pre-check that validates source and destination directories before planning.
- Ensure the move log records both successes and rollbacks clearly.
- Re-run until all tests pass.
Checkpoint: All modifications done, tests still pass. Good time to review your changes.
Explain it (teach-back)¶
- Why does the mover use a two-phase approach (plan then execute) instead of moving immediately?
- How does
resolve_collisionavoid infinite loops — what guarantees it terminates? - Why does
_rollbackiterate in reverse order? - What are the risks of
shutil.moveacross different filesystems?
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¶
Stuck? Ask AI¶
If you are stuck after trying for 20 minutes, use one of these prompts:
- "I am working on Path Safe File Mover. I got this error: [paste error]. Can you explain what this error means without giving me the fix?"
- "I am trying to prevent file name collisions when moving files. Can you explain strategies for handling duplicate file names?"
- "Can you explain the difference between
shutil.move()andPath.rename()and when to use each?"
| ← Prev | Home | Next → |
|---|---|---|