Skip to main content

expansions/get_file_paths.py

1from collections.abc import Iterator
2from pathlib import Path
5def get_file_paths_under(
6 root: Path | str = Path("."), *, suffix: str = ""
7) -> Iterator[Path]:
8 """
9 Generates the absolute paths to every matching file under ``root``.
10 """
11 root = Path(root)
13 if root.exists() and not root.is_dir():
14 raise ValueError(f"Cannot find files under non-directory: {root!r}")
16 if not root.is_dir():
17 raise FileNotFoundError(root)
19 for dirpath, _, filenames in root.walk():
20 for f in filenames:
21 if not suffix or f.lower().endswith(suffix):
22 yield dirpath / f
25for p in get_file_paths_under():
26 {cursor}