INNER CODE UNIT · Python
browse_directory
virajmavani/semi-auto-image-annotation-tool · web/backend/main.py:526
async def browse_directory(path: str = "~"):
"""List subdirectories at the given path for the directory browser UI"""
try:
dir_path = Path(path).expanduser().resolve()
if not dir_path.is_relative_to(Path.home()):
raise HTTPException(status_code=400, detail="Path is outside the allowed directory")
if not dir_path.exists() or not dir_path.is_dir():
raise HTTPException(status_code=400, detail="Invalid directory path")
entries = []
try:
for entry in sorted(dir_path.iterdir()):
if entry.is_dir() and not entry.name.startswith('.'):
entries.append({
"name": entry.name,
"path": str(entry),