Skip to content

Instantly share code, notes, and snippets.

@VictorVelarde
Last active July 19, 2017 12:38
Show Gist options
  • Save VictorVelarde/238f2723539841d5d1a8b9584adac5a3 to your computer and use it in GitHub Desktop.
Save VictorVelarde/238f2723539841d5d1a8b9584adac5a3 to your computer and use it in GitHub Desktop.
Recursive search for files with pattern in a directory
# 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