This commit is contained in:
2026-03-10 20:21:31 +05:00
commit ec82b528a3
14 changed files with 1041 additions and 0 deletions

32
read_path.py Normal file
View File

@@ -0,0 +1,32 @@
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"]