Skip to content

Instantly share code, notes, and snippets.

@giasuddin90
Created October 30, 2019 11:13
Show Gist options
  • Save giasuddin90/42b0dce8d4a0eb8f34ae675264f80b0c to your computer and use it in GitHub Desktop.
Save giasuddin90/42b0dce8d4a0eb8f34ae675264f80b0c to your computer and use it in GitHub Desktop.
Python read file from a directory by using file extension
__author__ = 'giasuddin'
import os
import fnmatch
images = ['*.css', '*.jpeg', '*.ico', '*.gif', '*.png']
file_path= '/home/giasuddin/pyramid_sites/test//css'
for (dirpath, dirnames, filenames) in os.walk(file_path):
for extensions in images:
for filename in filenames:
if fnmatch.fnmatch(filename, extensions):
print(filename)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment