def print_tree(entries, indent=0):
# Group by parent directory
by_parent = {}
for entry in entries:
parent = "/".join(entry.path.split("/")[:-1])
by_parent.setdefault(parent, []).append(entry)
def print_dir(path, level):
children = by_parent.get(path, [])
for child in sorted(children, key=lambda e: e.name):
prefix = " " * level
icon = "📁" if child.type == "dir" else "📄"
print(f"{prefix}{icon} {child.name}")
if child.type == "dir":
print_dir(child.path, level + 1)
print_dir("/home/user", 0)
entries = sandbox.files.list("/home/user", depth=5)
print_tree(entries)