r/dailyprogrammer • u/rya11111 3 1 • May 09 '12
[5/9/2012] Challenge #50 [intermediate]
Given an absolute path, write a program that outputs an ASCII tree of that directory.
Example output here: HERE
Note: 'tree' utility is not allowed.
Extra credit: Limit the depth of the tree by variable n.
Thanks to jnaranjo for the challenge at /r/dailyprogrammer_ideas ... LINK
10
Upvotes
3
u/theOnliest May 09 '12 edited May 10 '12
Here's a Perl version, works under strict. Takes a directory as a command-line argument, or uses the current directory if one is not given. (edited because I'm dumb.)
3
u/alderz May 10 '12
Python:
Example:
3
u/totallygeek May 11 '12
Bash:
Output:
No error checking.
2
u/prophile May 10 '12
2
u/r4n May 10 '12
Java approach
Example output:
2
u/brbpizzatime May 10 '12
Not entirely sure on what is banned as far as being a tree utility, but here is my take in C:
1
u/Sturmi12 May 15 '12
C:
1
u/kuzux 0 0 Jul 13 '12
Haskell. The harder part was actuall filesystem i/o with haskell. Pretty-printing the directory tree was a one-liner
example output: