# recursive directory listing fn tree_walk(path, prefix) do const items = vfs:entries(path) if (items == :nil) return :nil for index in 0..items:len() do const entry = items[index] const last = index == items:len() - 1 let branch = "|-- " # font doesnt support fancy ascii symbols if (last) branch = "`-- " const slash = if (entry.type == 2) "/" else "" puts("#{prefix}#{branch}#{entry.name}#{slash}\n") if entry.type == 2 do const child = if (path == "/") "/#{entry.name}" else "#{path}/#{entry.name}" let indent = "| " if (last) indent = " " tree_walk(child, prefix ~ indent) end end end const context = env.ctx const target = if (context.argv:len() > 1) expand_path(context.argv[1]) else wd.path if vfs:is_dir(target) == :false do fail("tree: #{target}: not a directory\n") end else do puts("#{target}\n") tree_walk(target, "") end