如何得到相同的顺序从目录中的文件在Windows资源管理器?资源管理器、顺序、文件、目录中

2023-09-04 22:38:37 作者:故人少别离

可能重复:   自然排序在C#

我怎么可以读取目录中的文件中相同的顺序显示在Windows资源管理器?

how can I read the files from a directory in the same order as displayed in the windows explorer?

例如,Windows资源管理器列表:

For example, the windows explorer lists:

file 1.txt
file 2.txt
file 3.txt
file 4.txt
file 5.txt
file 6.txt
file 7.txt
file 8.txt
file 9.txt
file 10.txt
file 11.txt
file 12.txt

而Directory.GetFiles()列出了:

while Directory.GetFiles() lists:

file 1.txt
file 10.txt
file 11.txt
file 12.txt
file 2.txt
file 3.txt
file 4.txt
file 5.txt
file 6.txt
file 7.txt
file 8.txt
file 9.txt

在这里你可以找到这个另一种解决方案: HTTP: //www.$c$cproject.com/KB/recipes/csnsort.aspx?msg=3342284

Here you can find another solution for this: http://www.codeproject.com/KB/recipes/csnsort.aspx?msg=3342284

推荐答案

这是特别定制了一个新功能添加在WinXP中的。你最好的选择将是重新实现相同的排序算法(见上文如何做到这一点的链接)的集合,一旦你已经装载使用 Directory.GetFiles()集合

That special ordering was a new feature added in WinXP. Your best bet would be to re-implement the same sorting algorithm (see the link above for how to do it) on the collection once you've loaded the collection using Directory.GetFiles().