2014-05-18 19:05:31 +02:00
|
|
|
import fnmatch
|
|
|
|
import os
|
|
|
|
|
|
|
|
# constants
|
2015-05-17 11:49:35 +02:00
|
|
|
PATH = './'
|
2016-12-17 17:22:43 +01:00
|
|
|
PATTERN = '*.md'
|
2014-05-18 19:05:31 +02:00
|
|
|
|
|
|
|
|
|
|
|
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:
|
2015-05-17 11:49:35 +02:00
|
|
|
print("Found {} files:".format(len(matches)))
|
2014-05-18 19:05:31 +02:00
|
|
|
output_files(matches)
|
|
|
|
else:
|
2015-05-17 11:49:35 +02:00
|
|
|
print("No files found.")
|
2014-05-18 19:05:31 +02:00
|
|
|
else:
|
2015-05-17 11:49:35 +02:00
|
|
|
print("Sorry that path does not exist. Try again.")
|
2014-05-18 19:05:31 +02:00
|
|
|
|
|
|
|
|
|
|
|
def output_files(list_of_files):
|
|
|
|
for filename in list_of_files:
|
2015-05-17 11:49:35 +02:00
|
|
|
print(filename)
|
2014-05-18 19:05:31 +02:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2016-12-17 17:22:43 +01:00
|
|
|
get_file_names(PATH, PATTERN)
|