mirror of
https://github.com/openswarm-ai/openswarm.git
synced 2026-09-11 12:17:45 +02:00
20 lines
603 B
Python
20 lines
603 B
Python
import os
|
|
from typing import Dict
|
|
from typeguard import typechecked
|
|
|
|
@typechecked
|
|
def walk_directory(folder: str) -> Dict[str, str]:
|
|
files: Dict[str, str] = {}
|
|
if not os.path.isdir(folder):
|
|
return files
|
|
for root, _dirs, filenames in os.walk(folder):
|
|
for fname in filenames:
|
|
full_path = os.path.join(root, fname)
|
|
rel_path = os.path.relpath(full_path, folder)
|
|
try:
|
|
with open(full_path, encoding="utf-8") as f:
|
|
files[rel_path] = f.read()
|
|
except Exception:
|
|
pass
|
|
return files
|