Last active
January 16, 2018 18:33
-
-
Save riccardodivirgilio/98b3d10483ffa234f04c236149faa087 to your computer and use it in GitHub Desktop.
Recursive Find File utility
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 | |
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