Level 3 / Project 07 - Batch File Auditor¶
Home: README
Learn Your Way¶
| Read | Build | Watch | Test | Review | Visualize | Try |
|---|---|---|---|---|---|---|
| — | This project | — | — | Flashcards | — | Browser |
Estimated time: 45 minutes
Focus¶
- scan many files with diagnostics
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-3/07-batch-file-auditor
python project.py audit .
python project.py audit . --pattern "*.py" --json
python project.py scan .
pytest -q
Expected terminal output¶
Audit: .
Files: 5, Total size: 12,345 bytes
Issues (2):
[WARNING] empty.txt: File is empty (0 bytes)
[INFO ] notes: File has no extension
10 passed
Expected artifacts¶
- Audit report on stdout
- Passing tests
- Updated
notes.md
Checkpoint: Baseline code runs and all tests pass. Commit your work before continuing.
Alter it (required) — Extension¶
- Add CSV export of audit results with columns: filename, size, last_modified, status.
- Add a
--recursiveflag to scan subdirectories. - Add a
check_encodingfunction that flags non-UTF-8 files.
Break it (required) — Core¶
- Point the auditor at a file instead of a directory — what error appears?
- Audit a directory with no files — does the summary handle zero files?
- Use a glob pattern that matches nothing — what does the report show?
Fix it (required) — Core¶
- Add a clear error message for non-directory input.
- Handle permission errors when scanning protected directories.
- Show "No files match pattern" instead of an empty report.
Checkpoint: All modifications done, tests still pass. Good time to review your changes.
Explain it (teach-back)¶
- How does
Path.glob()differ fromPath.rglob()? - Why separate each check into its own function (check_empty, check_large, etc.)?
- What is
Path.stat()and what metadata does it provide? - How does the
@dataclassfield(default_factory=list)pattern work?
Mastery check¶
You can move on when you can: - scan directories with pathlib and glob patterns, - build composable check functions that return structured results, - aggregate check results into a summary report, - use dataclasses for structured audit data.
Related Concepts¶
| ← Prev | Home | Next → |
|---|---|---|