Last active
August 14, 2019 09:39
-
-
Save winnydejong/11c9fbe8e41830207070b550c5f56885 to your computer and use it in GitHub Desktop.
Python function to list all files with a certain extension
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
# 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