RosettaCodeData/Task/Visualize-a-tree/Zkl/visualize-a-tree.zkl

21 lines
562 B
Plaintext

fcn vaultDir(out=Console){
const INDENT=" ";
space:=""; lastPath:=L();
foreach fullname in (TheVault.BaseClass.contents.sort()){
path:=fullname.split("."); name:=path.pop();
if(lastPath==path) out.writeln(space,name);
else{
n:=0; p:=path.copy();
try{
while(path[0]==lastPath[0])
{ n+=1; path.pop(0); lastPath.pop(0); }
}catch{}
space=INDENT*n;
foreach dir in (path){ out.writeln(space,dir); space+=INDENT; }
out.writeln(space,name);
lastPath=p;
}
}
"" // so startup has something to display
}