How can I get files the same order they are on the hard disk ?

Nedudale 141 Reputation points
2021-10-29T23:38:00.633+00:00

I tried this two options :

var images = System.IO.Directory.GetFiles(radarFolderImagesDownload,  
                                  "*.gif", SearchOption.AllDirectories).OrderBy(x => x).ToArray();  

var sorted = Directory.GetFiles(radarFolderImagesDownload).OrderBy(f => f);  

but the result in both cases is the same the files are not sorted as they are ordered on the hard disk :

The files have numbers and in images for example the order is 0,1,10....then 19,2,20,21...

145113-0110.jpg

And the order they are on the hard disk :

145114-0101.jpg

The problem is later if I want to play with timer the images on a pictureBox they will not be played in the same order as on the hard disk.

Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,828 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,247 questions
0 comments No comments
{count} votes

Accepted answer
  1. Castorix31 81,726 Reputation points
    2021-10-30T00:02:47.48+00:00

    Same question as how-can-i-get-files-from-the-hard-disk-as-array-in.html

    (I posted the method used by Explorer, which sorts 0,1, 2, ...
    karenpayneoregon posted another method that I did not test, but which seems to work too...


0 additional answers

Sort by: Most helpful