A lot of automation is a folder: exports land in inbox/ every day, a script picks them up, and the finished files move to archive/. pathlib handles all of it: Path("inbox").iterdir() lists a folder, p.suffix and p.name describe a file, mkdir(parents=True, exist_ok=True) creates folders, and rename moves a file.
Real folders are messier than examples:
- An export tool writes
.CSV in capitals, and someone leaves notes.txt in the folder.
- A file saved from Excel starts with a byte order mark, so the first column name reads
\ufefforder_id unless you open it with encoding="utf-8-sig".
rename on Linux and macOS silently replaces a file that is already there.
- The script runs again tomorrow, so it must remember what it already processed.
Each exercise runs in a fresh copy of the folder.
Out: ('2026-03-03_orders.CSV', '2026-03-03_orders', '.CSV', True). Compare suffixes in lowercase.