How do I plot the content of a directory and all its subdirectories into infinity using TreeForm? I've tried using a mix of FileNames, StringSplit and GatherBy but in the end I couldn't find even a promising start.
|
Here's a relatively straightforward "first version":
This has a very poor display capacity if there are more than a certain number of files in a directory level. It would need a lot of work to make the presentation reasonable in the general case. But this form of tree presentation of a file system also has a lot of potential. For example, you could build a graphical navigation system based on this (though not necessarily with |
|||||||
|
|
The following is a slight modification to @amr's code. It shows a directory tree using
|
||||
|
|
|
Here is the code required to implement Hypnotoad's solution (see comment to the question). I've copied Leonid's code over from its original thread. The one problem I had with this solution was that
|
|||
|
|

makeTreefunction in Leonid's answer on implementing Tries. By redefining the RHS of the first line in the definition asmakeTree[StringSplit[wrds, "/"]], you can get a good structure for the directory tree withmakeTree@FileNames["*", {"*"}, ∞](you'll have to clean up the{{} -> {}}). While this can't be plugged in a built-in graph function likeGraphorTreePlot, it can be easily converted to a graph using some custom code. – rm -rf♦ Jan 7 at 4:48