I’m using MongoDB and I need to write an algorithm to fill the following classes, to build a tree directory structures:
public class Dir
{
public string name { get; set; }
public string hash { get; set; }
public bool read { get; set; }
public bool write { get; set; }
public Dir[] dirs { get; set; }
}
I will get form MongoDB a List strings of the folders like this, distinct and sorted (empty string is the root):
Folder1
Folder2
Folder2/ChildFolder
Folder2/ChildFolder2
Folder2/ChildFolder3
Folder2/ChildFolder3/Folderrrr
Folder2/ChildFolder3/Hi
""
I should have a Dir object which is the root folder, and inside that one I should have an array of directories, on each directory I could have another array of directories and so one…
Any idea? Thanks for any help
Works fine with your example data, but may be need to make some updates in future