Skip to content

Instantly share code, notes, and snippets.

@winnydejong
Last active August 14, 2019 09:39
Show Gist options
  • Save winnydejong/11c9fbe8e41830207070b550c5f56885 to your computer and use it in GitHub Desktop.
Save winnydejong/11c9fbe8e41830207070b550c5f56885 to your computer and use it in GitHub Desktop.
Python function to list all files with a certain extension
# function that lists files based on filetype
def listFiles(dr, ext):
return glob(path.join(dr,"*.{}".format(ext)))
# example of function: when you want to list all pdfs in working dir
pdfs = listFiles('','pdf')
# example of function: when you want to list all txts in home dir
txts = listFiles('/Users/Name','txt')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment