C# How do I use Directory.GetFiles() to get files that have the same order as in Windows explorer?

前端 未结 7 987
萌比男神i
萌比男神i 2020-12-11 19:12

Is is possible to get files that is ordered same as in Windows Explorer

I know \"natural sort\", but it\'s not what I need, I need to get the file list ordered by th

7条回答
  •  时光说笑
    2020-12-11 19:59

    Here's how to get a list of files sorted by their name:

    var path = @"C:\windows"; // obviously change this to whatever you want
    var files = System.IO.Directory.GetFiles (path).ToList ();
    file.Sort();
    

    And that's it!

    Here's how you would do it per your given code sample:

    var temperaturePressureSignalFilesList = Directory.GetFiles(TemperaturePressureSignalDirectory, "*.txt", SearchOption.TopDirectoryOnly).ToList();
    temperaturePressureSignalFilesList.Sort();
    

提交回复
热议问题