开发者

Sorting array of directory paths by actual directory structure

开发者 https://www.devze.com 2023-02-21 18:46 出处:网络
I have an array of directories (a search which includes subdirectories). I\'d like to sort the results, like so:

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消