Given a List of Strings to each file within the structure
var paths = new List<string> {"root_folder/a first folder/holidays.mov", "root_folder/a first folder/javascript-file.js", etc...}
I need to output a String that represents the directory structure
root_folder/
|-- a first folder/
| |-- holidays.mov
| |-- javascript-file.js
| `-- some_picture.jpg
|-- documents/
| |-- spreadsheet.xls
| |-- manual.pdf
| |-- document.docx
| `-- presentation.ppt
| `-- test
|-- empty_folder/
|-- going deeper/
| |-- going deeper/
| | `-- going deeper/
| | `-- going deeper/
| | `-- .secret_file
| |-- style.css
| `-- index.html
|-- music and movies/
| |-- great-song.mp3
| |-- S01E02.new.episode.avi
| |-- S01E02.new.episode.nfo
| `-- track 1.cda
|-- .gitignore
|-- .htaccess
|-- .npmignore
|-- archive 1.zip
|-- archive 2.tar.gz
|-- logo.svg
`-- README.md
I found some information for the TreeView control but I just need to output a String.
Any help would be appreciated.
2
Answers
Managed to get the directory structure with this class I've made:
To use simply declare a
CodeComparisonToolDirBuilder
at the root folder/node. This was inspired by Building Tree Structure from a list of string pathsWell, a treeview is kind of ideal, since you can then provide a windows like explorer view, and do so in a web page. the result is a VERY nice interface.
However, you can also use the windows command line, and use the "tree" command, and it will output files and a tree like structure.
So, say this:
So, you can use shell() command, and capture the output of the windows command "tree", and it does quite a nice job.
It really depends on what you want to do with the final output.
Overall, it not a whole lot less code to use a treeview, since as such, they can be recursive.