Spaces:
Paused
Paused
Rafael Uzarowski commited on
feat: files.get_subdirectories include and exclude can now be lists
Browse files- python/helpers/files.py +7 -3
python/helpers/files.py
CHANGED
|
@@ -250,16 +250,20 @@ def get_base_dir():
|
|
| 250 |
return base_dir
|
| 251 |
|
| 252 |
|
| 253 |
-
def get_subdirectories(relative_path: str, include: str = "*", exclude=None):
|
| 254 |
abs_path = get_abs_path(relative_path)
|
| 255 |
if not os.path.exists(abs_path):
|
| 256 |
return []
|
|
|
|
|
|
|
|
|
|
|
|
|
| 257 |
return [
|
| 258 |
subdir
|
| 259 |
for subdir in os.listdir(abs_path)
|
| 260 |
if os.path.isdir(os.path.join(abs_path, subdir))
|
| 261 |
-
and fnmatch(subdir, include)
|
| 262 |
-
and (exclude is None or not fnmatch(subdir, exclude))
|
| 263 |
]
|
| 264 |
|
| 265 |
|
|
|
|
| 250 |
return base_dir
|
| 251 |
|
| 252 |
|
| 253 |
+
def get_subdirectories(relative_path: str, include: str | list[str] = "*", exclude: str | list[str] | None = None):
|
| 254 |
abs_path = get_abs_path(relative_path)
|
| 255 |
if not os.path.exists(abs_path):
|
| 256 |
return []
|
| 257 |
+
if isinstance(include, str):
|
| 258 |
+
include = [include]
|
| 259 |
+
if isinstance(exclude, str):
|
| 260 |
+
exclude = [exclude]
|
| 261 |
return [
|
| 262 |
subdir
|
| 263 |
for subdir in os.listdir(abs_path)
|
| 264 |
if os.path.isdir(os.path.join(abs_path, subdir))
|
| 265 |
+
and any(fnmatch(subdir, inc) for inc in include)
|
| 266 |
+
and (exclude is None or not any(fnmatch(subdir, exc) for exc in exclude))
|
| 267 |
]
|
| 268 |
|
| 269 |
|