Sorting array of directory paths by actual directory structure
I have an array of directories (a search which includes subdirectories). I'd like to sort the results, like so:
Test
--开发者_如何学C-A
----A.A
---B
So the collection lists the directory, and then all of the directories within it, and so forth, for every directory.
How could I sort an array like this?
Thanks
If sorting this alphabetically will do this for you (which I think it should)...
With
string[] dirs = Directory.GetDirectories(@"C:\");
You should be able to use
string[] sorted = dirs.OrderBy(d => d).ToArray();
or
Array.Sort(dirs);
If your search is recursive you don't need sorting.
精彩评论