list files in directory ordered by creation time
-
hello, I`m using this code, but it return files in alphabetic order, I need to list those files in date modified order. string winDir = "../katalogas"; try { string[] files = Directory.GetFiles(winDir); foreach (string fileName in files) { // // } } catch (IOException ex) { MessageBox.Show("Klaida! Nerandamas formų katalogas." + ex.Message); Close(); } }
-
hello, I`m using this code, but it return files in alphabetic order, I need to list those files in date modified order. string winDir = "../katalogas"; try { string[] files = Directory.GetFiles(winDir); foreach (string fileName in files) { // // } } catch (IOException ex) { MessageBox.Show("Klaida! Nerandamas formų katalogas." + ex.Message); Close(); } }
I believe that it doesn't return the files in any specific order at all. They just happen to be ordered alphabetically in the directory. Probably because you have moved the folder (as that creates a new folder and moves the files) or have run defrag (which sorts the files in the directories). You need to get more information about the files than just the name. Use DirectoryInfo.GetFiles to get FileInfo-object for the files. Make a Comparer for two FileInfo-objects that compares the property you want to sort on, and use that in the Array.Sort method. --- b { font-weight: normal; }