Last active
August 29, 2015 14:07
-
-
Save achavez/b1c6560f8af7267c76c3 to your computer and use it in GitHub Desktop.
Get all files in a directory with a specific file extension
This file contains 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 | |
def list_files(source, extension): | |
matches = [] | |
for root, dirnames, filenames in os.walk(source): | |
for filename in filenames: | |
if filename.endswith((extension)): | |
print filename | |
# Ex: Get all files in the directory docs with the extension PDF | |
# Can be easily written to a text file by running at the command line: python file_list.py > file_list.txt | |
list_files('docs', '.pdf') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment