Given a directory and a suffix, recursively find all files matching the suffix. Directories or files with names beginning with a . are ignored, but hidden flags on filesystems are not checked. When provided with a suffix `None`, there is no suffix-based filtering.
(path: Path, suffix: Optional[str] = None)
| 266 | |
| 267 | |
| 268 | def walk_directory(path: Path, suffix: Optional[str] = None) -> List[Path]: |
| 269 | """Given a directory and a suffix, recursively find all files matching the suffix. |
| 270 | Directories or files with names beginning with a . are ignored, but hidden flags on |
| 271 | filesystems are not checked. |
| 272 | When provided with a suffix `None`, there is no suffix-based filtering.""" |
| 273 | if not path.is_dir(): |
| 274 | return [path] |
| 275 | paths = [path] |
| 276 | locs = [] |
| 277 | seen = set() |
| 278 | for path in paths: |
| 279 | if str(path) in seen: |
| 280 | continue |
| 281 | seen.add(str(path)) |
| 282 | if path.parts[-1].startswith("."): |
| 283 | continue |
| 284 | elif path.is_dir(): |
| 285 | paths.extend(path.iterdir()) |
| 286 | elif suffix is not None and not path.parts[-1].endswith(suffix): |
| 287 | continue |
| 288 | else: |
| 289 | locs.append(path) |
| 290 | # It's good to sort these, in case the ordering messes up cache. |
| 291 | locs.sort() |
| 292 | return locs |
| 293 | |
| 294 | |
| 295 | def _format_number(number: Union[int, float], ndigits: int = 2) -> str: |
searching dependent graphs…