Begin with a deterministic task

You do not need an LLM to list filenames and file sizes. A short script performs this task consistently and makes the method visible. Save AI for operations where interpretation is needed.

This exercise uses Python 3 and only its standard library. Install Python from its official website first. In your terminal, confirm the version with python --version on Windows or python3 --version on macOS/Linux. If that command is unavailable, follow the installation instructions rather than pasting a chain of unrelated fixes.

Prepare the folder

Create a folder called inventory-lab. Inside it, create a folder called practice-docs and add three fictional text files. Save the following code as inventory.py beside that folder. The script prints CSV to the terminal. It does not rename, move, or write to the input files.

python
from pathlib import Path
import csv
import sys

root = Path("practice-docs")
if not root.is_dir():
    raise SystemExit("Create practice-docs beside this script first.")

writer = csv.writer(sys.stdout, lineterminator="\n")
writer.writerow(["relative_path", "bytes"])
for item in sorted(root.rglob("*")):
    if item.is_file() and not item.is_symlink():
        writer.writerow([item.relative_to(root).as_posix(), item.stat().st_size])

Open a terminal in inventory-lab and run:

sh
python inventory.py

Use python3 instead if that is your installed command. If a filename contains a comma, the CSV writer handles quoting. Do not build CSV rows by joining raw fields with commas. [source]

Understand each operation

Path represents a filesystem path. is_dir() checks the input folder. rglob("*") finds descendants. The loop processes items one at a time. The condition selects files and skips symbolic-link file entries. relative_to(root) removes the practice folder prefix, and stat().st_size obtains the size in bytes. [source]

Run this exercise only on your controlled practice folder. The example is an introductory inventory, not a hardened scanner for hostile directory structures or a forensic collection tool.

Predict before you run

Add a nested folder with one more text file. Predict the new row. Change a file's contents and predict which field changes. Rename a file and observe that this simple path-based inventory cannot by itself establish that it is the same document.

That limitation introduces a design question: later systems may need stable document IDs, hashes, or version records. A script is easier to extend when you understand exactly what its current fields establish.

Try it: diagnose a zero-row result

The header appears, but no file rows do. What should you inspect?

Check your understanding

Check that you ran the script from the intended working directory and that practice-docs contains ordinary files. The working directory affects this relative path. A successful process exit does not establish that the expected input was present. Compare the expected file count with the actual output.