Skip to content

Instantly share code, notes, and snippets.

@simonLeary42
Last active January 9, 2024 17:26
Show Gist options
  • Select an option

  • Save simonLeary42/646ad533d8d6c0a762e00ade1b151cd6 to your computer and use it in GitHub Desktop.

Select an option

Save simonLeary42/646ad533d8d6c0a762e00ade1b151cd6 to your computer and use it in GitHub Desktop.
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