Created
June 18, 2020 03:17
-
-
Save Keiku/0c1d5df2d7726fcf67a834462176982a to your computer and use it in GitHub Desktop.
Get image paths.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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