This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
legomaniack's profile picture

[Request] Windows Tree Command

Started by legomaniack, 07 February 2012 - 10:00 PM
legomaniack #1
Posted 07 February 2012 - 11:00 PM
I was wondering, if you could have a program that visually lists the file structure, like the windows command "tree"

for example, if i have Folder1 with File 1 in it, and Folder 2 with Folder 3 and file 2 in it, and Folder 3 has file 3 in it, and file 4 is back in the hdd.

[ VEIW ATTACHED TXT FILE ]

I think this would be useful, as it helps some to visualize file structure.

EDIT: Ok, so its possible, but i don't have enough lua knowledge to make it. Anyone?
Casper7526 #2
Posted 08 February 2012 - 12:00 AM
yes that's certainly possible, the "ls" command returns a table of data, and then you would loop through that table of data and add appropriate markings based on if the table contains folders or files.
Espen #3
Posted 08 February 2012 - 01:37 PM
I've played around a little for curiosity's sake.
As far as I've tested, basic functionality should work. At the moment you can't tell it the maximum level of traversal.
That means it traverses EVERY directory it finds, so use with caution (or terminate it with CTRL+T :P/>/>).
Code: http://pastebin.com/bggiSgmc

I'm not happy with the handling of the command arguments, I've just hastily hacked that together at the end. So just ignore that for now.^^
For help on how to use it type:
tree -h