You've gotten some good answers here and on SO to your questions, but you're missing a non-recursive solution. Here's how I went about trying to solve the problem (Note that it is currently slightly broken!):
private static IEnumerable<string> GetPaths(int maxDepth, int iterations, string root) { var depths = Enumerable.Range(0, maxDepth); var widths = Enumerable.Range(0, iterations); var thing = depths.Select(x => Path.Combine( depths .Reverse() .Skip(x + 1) .Select(y => y.ToString()) .Reverse() .ToArray())); return thing.SelectMany(x => widths.Select(y => Path.Combine(root, x, y.ToString()))); }
What this essentially does is create all the sets of combinations by joining collections, and then combines them into paths. The result is that every depth is covered, without any chance of blowing the stack. There is a bug currently: the variable thing (which should be renamed, should you take this route) contains (with an input of 10, 10, "temp" the paths:
0\1\2\3\4\5\6\7\8 0\1\2\3\4\5\6\7 0\1\2\3\4\5\6 0\1\2\3\4\5 0\1\2\3\4 0\1\2\3 0\1\2 0\1 0 string.Empty
I'll leave it to you to figure out how to fix it, but it's very simple.
iterationsand an argument. We'd need to see what stuff you need to do to be able to give a really good answer.