test
This commit is contained in:
32
read_path.py
Normal file
32
read_path.py
Normal 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"]
|
||||
|
||||
Reference in New Issue
Block a user