Skip to content

Instantly share code, notes, and snippets.

@riccardodivirgilio
Last active January 16, 2018 18:33
Show Gist options
  • Save riccardodivirgilio/98b3d10483ffa234f04c236149faa087 to your computer and use it in GitHub Desktop.
Save riccardodivirgilio/98b3d10483ffa234f04c236149faa087 to your computer and use it in GitHub Desktop.
Recursive Find File utility
import os
def findfiles(files, test = lambda path: os.path.splitext(path)[1].lower() == '.xlsx'):
if isinstance(files, str):
files = [files]
for path in files:
if os.path.isdir(path):
for root, dirs, files in os.walk(path):
for f in files:
if test(f):
yield os.path.join(root, f)
else:
if os.path.exists(path) and test(path):
yield path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment