Last active
July 19, 2017 12:38
-
-
Save VictorVelarde/238f2723539841d5d1a8b9584adac5a3 to your computer and use it in GitHub Desktop.
Recursive search for files with pattern in a directory
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
# traverse root directory, and list directories as dirs and files as files | |
# adapted from 'https://stackoverflow.com/a/16974952/251834' | |
import os | |
import fnmatch | |
baseFolder = '.' | |
pattern = '*.csv' | |
for root, dirs, files in os.walk(baseFolder): | |
path = root.split(os.sep) | |
print((len(path) - 1) * '---', os.path.basename(root)) | |
for file in files: | |
if fnmatch.fnmatch(file, pattern): | |
print(len(path) * '---', file) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment