Files
drobboxordinacebackup/indexer/scanner.py
2026-02-09 20:16:37 +01:00

31 lines
1.0 KiB
Python

import os
from datetime import datetime
def scan_files(root_path: str) -> dict:
"""
Projde celý adresářový strom a vrátí dict všech souborů.
Nehasuje obsah — to se dělá až pro změněné soubory.
Returns:
{relative_path: {full_path, file_name, directory, size, mtime}}
"""
result = {}
for root, _, files in os.walk(root_path):
for name in files:
full_path = os.path.join(root, name)
try:
stat = os.stat(full_path)
except (FileNotFoundError, PermissionError):
continue
rel_path = os.path.relpath(full_path, root_path).replace("\\", "/")
rel_dir = os.path.relpath(root, root_path).replace("\\", "/")
result[rel_path] = {
"full_path": full_path,
"file_name": name,
"directory": rel_dir,
"size": stat.st_size,
"mtime": datetime.fromtimestamp(stat.st_mtime),
}
return result