I'm fairly new to C#
and I'm attempting to take the tree structure I've created from a list, and write that to the file system. (I've used this answer).
That is, I want to create the directories and subdirectories in the proper depth. However, I'm getting stuck on depth and cannot think of how to loop through each iteration of the depth, then back out to start writing again, without just writing all the 0-depth directories, then all the 1-depth directories, etc., in the same location.
I'm thinking there's another recursive routine/method/function
, but I just can't wrap my head around it. I'd like to get to the next level (ha) in my understanding of programming.
static void Test(IEnumerable<TreeItem<category>> categories, int deep = 0)
{
foreach (var c in categories)
{
for (int i = 0; i < deep; ++i) {
System.IO.Directory.CreateDirectory(c.Item.Name);
}
Test(c.Children, deep + 1);
}
}