I'm working in JavaScript, and have an array of filepaths:
['root/folder1', 'root/folder1/folderA', 'root/folder1/folderA/folderi', 'root/folder1/folderB', 'root/folder2', ...] and so on. The filepaths are in order, so 'folder1' will always be listed before 'folder1/folderA', and so on.
I need to convert this to a tree structure, which is leaving me stumped. I'm aiming for something like this (the next step will have files in each folder as well, so I need to prep for that):
allFolders = { root: { 'files': [], 'folders': { folder1: { 'files': [], 'folders': { folderA: {...}, folderB: {...} } }, folder2: {} } } } although I'm open to any structure that works. I need to be able to iterate over the final result to display a file tree like this:
root - folder1 -- folderA --- folderi -- folderB - folder2 I don't really have any code to show because I haven't got as far as producing anything that's even remotely useful.