23 lines
628 B
Python
23 lines
628 B
Python
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
|
|
SUPPORTED_EXTS = {".doc", ".docx", ".pdf", ".xls", ".xlsx", ".csv", ".ppt", ".pptx"}
|
|
|
|
|
|
def discover(path: Path) -> list[Path]:
|
|
if path.is_file():
|
|
if path.name.startswith("~$"):
|
|
return []
|
|
return [path] if path.suffix.lower() in SUPPORTED_EXTS else []
|
|
if not path.exists():
|
|
raise FileNotFoundError(path)
|
|
files = [
|
|
p
|
|
for p in path.rglob("*")
|
|
if p.is_file()
|
|
and not p.name.startswith("~$")
|
|
and p.suffix.lower() in SUPPORTED_EXTS
|
|
]
|
|
return sorted(files, key=lambda x: str(x))
|