Last active
January 9, 2024 17:26
-
-
Save simonLeary42/646ad533d8d6c0a762e00ade1b151cd6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| def string_matches_any_globs(x:str, globs:List[str]): | |
| return any(fnmatch.fnmatch(x, y) for y in globs) | |
| def find_files(walk_root_path:str, include_globs:List[str], exclude_globs:List[str]=None) -> list: | |
| """ | |
| excluding takes precidence over including | |
| """ | |
| output = [] | |
| for dirname, _, basenames in os.walk(walk_root_path): | |
| for basename in basenames: | |
| path = os.path.join(dirname, basename) | |
| if exclude_globs is not None and string_matches_any_globs(path, exclude_globs): | |
| continue | |
| if string_matches_any_globs(path, include_globs): | |
| output.append(path) | |
| return output |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment