This commit is contained in:
Michael Herman 2014-05-18 11:05:31 -06:00
parent a1f1e50a94
commit 239a0ff7ff
2 changed files with 33 additions and 1 deletions

View File

@ -0,0 +1,31 @@
import fnmatch
import os
# constants
PATH = '/../../../..'
PATTERN = '*.py'
def get_file_names(filepath, pattern):
matches = []
if os.path.exists(filepath):
for root, dirnames, filenames in os.walk(filepath):
for filename in fnmatch.filter(filenames, pattern):
# matches.append(os.path.join(root, filename)) # full path
matches.append(os.path.join(filename)) # just file name
if matches:
print "Found {} files:".format(len(matches))
output_files(matches)
else:
print "No files found."
else:
print "Sorry that path does not exist. Try again."
def output_files(list_of_files):
for filename in list_of_files:
print filename
if __name__ == '__main__':
all_files = get_file_names(PATH, PATTERN)

View File

@ -8,4 +8,5 @@
1. **06_execution_time.py**: class used for timing execution of code
1. **07_benchmark_permissions_loading_django.py**: benchmark loading of permissions in Django
1. **08_basic_email_web_crawler.py**: web crawler for grabbing emails from a website recursively
1. **08_basic_link_web_crawler.py**: web crawler for grabbing links from a website recursively
1. **09_basic_link_web_crawler.py**: web crawler for grabbing links from a website recursively
1. **10_find_files_recursively.py**: recursively grab files from a directory