Created
June 6, 2026 18:57
-
-
Save fitzy1321/bc5fd359005faa362637f5fe9604291d to your computer and use it in GitHub Desktop.
Search Path for File
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from pathlib import Path | |
| def find_file(p: Path, file_name: str) -> Path | None: | |
| if p.is_file() and file_name in p.parts: | |
| return p | |
| for sp in [p, *p.parents]: | |
| candidate = sp / file_name | |
| if candidate.exists() and candidate.is_file(): | |
| return candidate | |
| return None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment