def find(d, filterfn=None, abspath=False, glob=None, regex=None, dirs=False): """ Recursively walks directory `d` yielding files which satisfy `filterfn`. Set option `relpath` to False to output absolute paths. glob: shell glob filter function regex: regex filter function dirs: only search for directories matching filterfn """ assert atmost(1, [filterfn, glob, regex]) if filterfn is None: if glob is not None: filterfn = lambda x: fnmatch(x, glob) elif regex is not None: filterfn = re.compile(regex).match collection = directories(d, abspath=abspath) if dirs else files(d, abspath=abspath) for item in collection: if filterfn is None or filterfn(item): yield item
def find(d, filterfn=None, abspath=False, glob=None, regex=None, dirs=False): """ Recursively walks directory `d` yielding files which satisfy `filterfn`. Set option `relpath` to False to output absolute paths. glob: shell glob filter function regex: regex filter function dirs: only search for directories matching filterfn """ assert atmost(1, [filterfn, glob, regex]) if filterfn is None: if glob is not None: filterfn = lambda x: fnmatch(x, glob) elif regex is not None: filterfn = re.compile(regex).match collection = directories(d, abspath=abspath) if dirs else files( d, abspath=abspath) for item in collection: if filterfn is None or filterfn(item): yield item