Skip to content

Level 1 / Project 08 - Path Exists Checker

Home: README

Learn Your Way

Read Build Watch Test Review Visualize Try
Concept This project Quiz Flashcards Browser

Estimated time: 30 minutes

Focus

  • filesystem existence and type checks

Why this project exists

Check whether file paths exist, determine if each is a file or directory, and report sizes in human-readable format. You will learn pathlib.Path methods like exists(), is_file(), is_dir(), and stat().

Run (copy/paste)

Use <repo-root> as the folder containing this repository's README.md.

cd <repo-root>/projects/level-1/08-path-exists-checker
python project.py --input data/sample_input.txt
pytest -q

Expected terminal output

=== Path Checker ===

  data/sample_input.txt     EXISTS   file    0.1 KB
  data/output.json          EXISTS   file    0.3 KB
  /nonexistent/path/file    MISSING  --      --

  2/3 paths exist
5 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

  1. Add a "last modified" field showing when each file was last changed (use os.path.getmtime()).
  2. Add a --exists-only flag that only shows paths that actually exist.
  3. Re-run script and tests.

Break it (required) — Core

  1. Add a path with special characters like data/my file (1).txt -- does check_path() handle spaces in paths?
  2. Add a symbolic link (if on Linux/Mac) or a path to a network drive -- does it detect the type correctly?
  3. Add a very deeply nested path that does not exist -- does the checker handle long paths gracefully?

Fix it (required) — Core

  1. Ensure check_path() works with paths containing spaces by using Path objects consistently.
  2. Handle permission errors (e.g. restricted directories) by catching PermissionError.
  3. Add a test for the missing-path case.

Checkpoint: All modifications done, tests still pass. Good time to review your changes.

Explain it (teach-back)

  1. What does Path.exists() do and why is it better than os.path.exists()?
  2. Why does format_size() convert bytes to KB/MB/GB instead of just showing raw bytes?
  3. What is the difference between is_file(), is_dir(), and exists() on a Path object?
  4. Where would path checking appear in real software (deployment scripts, backup tools, file managers)?

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.



← Prev Home Next →