file 10
This commit is contained in:
parent
a1f1e50a94
commit
239a0ff7ff
31
10_find_files_recursively.py
Normal file
31
10_find_files_recursively.py
Normal 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)
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user