Files
kadastr-17/read_path.py
2026-03-10 20:21:31 +05:00

33 lines
899 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from pathlib import Path
from typing import List
def list_files_in_dir(dir_path: str, recursive: bool = False) -> List[str]:
"""
Возвращает список файлов в директории с их полными путями.
Args:
dir_path: путь к директории (строка или Path-подобный).
recursive: если True, включает файлы во всех поддиректориях.
Returns:
Список путей (строк) к файлам.
Raises:
FileNotFoundError: если директория не найдена.
"""
p = Path(dir_path)
if not p.exists():
raise FileNotFoundError(f"Directory not found: {dir_path}")
if recursive:
files = [str(f.resolve()) for f in p.rglob("*") if f.is_file()]
else:
files = [str(f.resolve()) for f in p.iterdir() if f.is_file()]
return files
__all__ = ["list_files_in_dir"]