Skip to content

Instantly share code, notes, and snippets.

@fitzy1321
Created June 6, 2026 18:57
Show Gist options
  • Select an option

  • Save fitzy1321/bc5fd359005faa362637f5fe9604291d to your computer and use it in GitHub Desktop.

Select an option

Save fitzy1321/bc5fd359005faa362637f5fe9604291d to your computer and use it in GitHub Desktop.
Search Path for File
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