Created
July 12, 2024 20:51
-
-
Save gustavofuhr/99191ed55a4a298efcf10d2d169ede90 to your computer and use it in GitHub Desktop.
Get all the image files from a dir path, including subdirs.
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 os | |
| import glob | |
| import functools, operator | |
| # extract image paths inside the image_dir_path including may include subdirectories using glob | |
| accepted_exts = [".jpg", ".jpeg", ".png"] | |
| image_files = [glob.glob(os.path.join(image_dir_path, "*"+ex)) for ex in accepted_exts] | |
| if include_subdirs: | |
| image_files.extend([glob.glob(os.path.join(image_dir_path + "/**/", "*"+ex)) for ex in accepted_exts]) | |
| image_files = functools.reduce(operator.iconcat, image_files, []) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment