I recently needed to process large, deeply nested image libraries and rename them using AI-generated, descriptive filenames and alt text. The catch: some clients want to keep their folder hierarchy intact; others prefer a single flat output directory with one consolidated log. Along the way, I also needed to ensure filenames only contain ASCII letters (e.g., Č/Š/Ž → c/s/z).
This guide walks through a practical, production-friendly CLI that solves exactly that.
What we'll build
A Python CLI that reads images from a nested input directory and, depending on your needs, either preserves the structure or flattens all outputs into one folder.
Flexible logging: per-folder, per-project, or a single central JSON/CSV.
ASCII-only filenames via diacritic replacement.
Conflict-safe saves in flat mode and resume/skip behavior using existing logs.
By the end, you'll be able to point the CLI at any image library and produce clean, AI-renamed outputs—mirrored or flattened—with consolidated logs.
1) Add flexible output and logging modes
We introduce a --log-mode option that controls both logging placement and the output directory structure. Options:
per_folder: mirror folders; put logs in each folder (default)
project_level: mirror folders; one log per top-level folder
central: mirror folders; single log in output root
Conceptually: central/project-level modes consolidate logs while preserving structure; flat mode consolidates both logs and files into a single directory.
2) Include filenames in results (JSON/CSV)
We log both the paths and the filenames to make downstream processing and deduping easier.
We built a practical CLI that handles real-world image libraries: AI-derived names and alt text, flexible folder strategies (mirrored or flat), consolidated logging, safe ASCII filenames, conflict handling, and resume support. Point it at any nested source and confidently generate clean, production-ready assets.
Let me know in the comments if you have questions, and subscribe for more practical development guides.