From 274d7993d5f4af69f1ad76f64bc678bd3fd37846 Mon Sep 17 00:00:00 2001 From: Rafael Uzarowski Date: Sat, 15 Mar 2025 14:22:18 +0100 Subject: [PATCH] feat: files.get_subdirectories include and exclude can now be lists --- python/helpers/files.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/python/helpers/files.py b/python/helpers/files.py index bc0e97eb9..15d7e6fc5 100644 --- a/python/helpers/files.py +++ b/python/helpers/files.py @@ -250,16 +250,20 @@ def get_base_dir(): return base_dir -def get_subdirectories(relative_path: str, include: str = "*", exclude=None): +def get_subdirectories(relative_path: str, include: str | list[str] = "*", exclude: str | list[str] | None = None): abs_path = get_abs_path(relative_path) if not os.path.exists(abs_path): return [] + if isinstance(include, str): + include = [include] + if isinstance(exclude, str): + exclude = [exclude] return [ subdir for subdir in os.listdir(abs_path) if os.path.isdir(os.path.join(abs_path, subdir)) - and fnmatch(subdir, include) - and (exclude is None or not fnmatch(subdir, exclude)) + and any(fnmatch(subdir, inc) for inc in include) + and (exclude is None or not any(fnmatch(subdir, exc) for exc in exclude)) ]