开发者

organize file paths in c#

is there a way if organizing paths depending on which one is more towards the root. For example if I have the paths:

"C:\someFolder\program files\b"
"C:\someFolder\X"
"C:\Z"
"C:\someFolder\program开发者_运维知识库 files\a"

then I will like to sort them as:

"C:\Z"
"C:\someFolder\X"
"C:\someFolder\program files\a"
"C:\someFolder\program files\b"

I am actually trying to create a tree view and that's why I want to sort them like that.


How about:

files.OrderBy(x => x.Split('\\').Length).ThenBy(x => x)


You could do a

pathName.Split('/').Length

on the path to get the number of levels deep, then sort on that number.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜