Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Get image paths.
import pathlib
# get image paths list in a directory
image_dir = pathlib.Path('images').resolve()
exts = ['.jpg', '.png']
image_paths = [path for path in image_dir.rglob('*') if path.suffix.lower() in exts]
# include parent directory
image_paths = [pathlib.Path(*path.parts[-2:]).as_posix() for path in image_dir.rglob('*') if path.suffix.lower() in exts]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.