Directory contents as Ascii tree

This shows how to print the contents of a directory as an Ascii tree. The output is similar to the ls -tree command under Unix/Linux.

def listRecursivly = { file, arg ->
println "${'|  ' * arg}`- ${file.getName()}\\"
file.eachFile() { f ->
if(f.directory) {
listRecursivly(f,(arg+1))
} else {
println "${'|  ' * (arg + 1)}`- ${f.getName()}"
}
}
}
listRecursivly (new File("."),0)

The output of this snippet looks like this.

`- test\
|  `- abc.txt
|  `- dir\
|  |  `- xyz.txt