Skip to content

Instantly share code, notes, and snippets.

@izikeros
Created June 2, 2022 17:34
Show Gist options
  • Select an option

  • Save izikeros/83bce3d2a60c4a800c4fac4cfb2bb1c8 to your computer and use it in GitHub Desktop.

Select an option

Save izikeros/83bce3d2a60c4a800c4fac4cfb2bb1c8 to your computer and use it in GitHub Desktop.
Code snippet with example for medium article
def get_images_in_dir(directory: str, extensions: List[str]) -> list:
"""
Get list of images in a directory, recursively. Include extensions:
.jpg, .png, cr2, etc.
:param directory: str
:param extensions: list
:return: list
"""
images = []
for root, dirs, files in os.walk(directory):
for file in files:
if file.lower().endswith(tuple(extensions)):
images.append(os.path.join(root, file))
return images
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment