Pathlib suggestion
Briefly

Pathlib suggestion
">>> from pathlib import Path >>> [x.name for x in Path('.').iterdir()] ['avocado.jpg', 'kiwifruit.jpg', 'lemon.jpg', 'apple.jpg', 'strawberry.jpg', 'rename-images.py', 'orange.jpg']"
"Pathlib can be used for globs as well, so has a lot of flexibility."
Pathlib offers an object-oriented interface for filesystem paths and operations via the Path class. Path('.').iterdir() yields Path objects representing directory entries. Accessing the .name attribute returns filenames directly, making directory listings concise. Pathlib includes globbing support through methods like Path.glob(), enabling pattern-based file matching. Pathlib reduces reliance on older modules like os.path and glob by combining path manipulation, checks, and file I/O into a single, consistent API that improves code readability and flexibility for common file operations.
[
|
]