Week 14 • Monday

Block 131: Filesystem Automation: os & pathlib

Automate file and directory operations from Python.

Concepts

Code Examples

See exercise below.

Exercise

Write a script that organizes files in a folder into subfolders by extension (.pdf/, .csv/, .jpg/ etc.). List all .csv files in a directory tree recursively with pathlib.

Homework

Why is pathlib preferred over os.path for new code? List 3 practical advantages.