Skip to content

Instantly share code, notes, and snippets.

@Keiku
Created June 18, 2020 03:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Keiku/0c1d5df2d7726fcf67a834462176982a to your computer and use it in GitHub Desktop.
Save Keiku/0c1d5df2d7726fcf67a834462176982a to your computer and use it in GitHub Desktop.
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