Recursively search for files matching a glob pattern and return the parent directory of the first match.
(root_path: str, pattern: str)
| 198 | |
| 199 | |
| 200 | def find_matching_dir(root_path: str, pattern: str) -> str: |
| 201 | """ |
| 202 | Recursively search for files matching a glob pattern and return the parent directory of the first match. |
| 203 | """ |
| 204 | matches = [ |
| 205 | Path(p) |
| 206 | for p in glob(f"{root_path}/**", recursive=True) |
| 207 | if Path(p).match(pattern) |
| 208 | ] |
| 209 | if not matches: |
| 210 | raise FileNotFoundError( |
| 211 | f"No files matching pattern '{pattern}' found under {root_path}" |
| 212 | ) |
| 213 | return str(matches[0].parent) |
| 214 | |
| 215 | |
| 216 | @comfy_node(name="LTXVGemmaCLIPModelLoader", description="Gemma 3 Model Loader") |