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.
精彩评论