Created
March 21, 2017 17:50
-
-
Save lucrib/65b79fc7f7256f2841932e541dfca91c to your computer and use it in GitHub Desktop.
A small script that receives a folder path and a extension and list all files of that extension recursively starting in the folder informed
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 | |
import sys | |
def list_files_in(path, ext=None): | |
for root, subdirs, files in os.walk(path): | |
# print('\n\nroot = ' + root) | |
for subdir in subdirs: | |
list_files_in(subdir) | |
for filename in files: | |
if extension and filename.lower().endswith(ext.lower()): | |
file_path = os.path.join(root, filename) | |
print(file_path) | |
if __name__ == '__main__': | |
try: | |
starting_path = str(sys.argv[1]) | |
extension = str(sys.argv[2]) | |
except IndexError as ie: | |
print 'Usage:\n\t' + sys.argv[0] + ' starting_path filter_extension' | |
sys.exit(0) | |
print('walk_dir = ' + starting_path) | |
print('walk_dir (absolute) = ' + os.path.abspath(starting_path)) | |
list_files_in(starting_path, extension) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment