Reading files in particular order?
.net, c#, file
Solution
List<FileInfo> files = directory
.GetFiles("*.txt")
.OrderBy(f => f.LastWriteTime)
.ToList();
See FileInfo and FileSystemInfo for a comprehensive list of fields you can order by.
Here's an example in VB.NET
Problem
I would like to read a lot of files from different folders. Now I asking myself what is the smartest way. For now Im using ``` DirectoryInfo directory = new DirectoryInfo(myPath); FileInfo[] files = directory.GetFiles("*.txt"); ``` so I have a list with all the files and I can iterate through them (read them one by one). Is that alright? Is there a way to reorder the list, so that I have always the oldest file at the top. Thats maybe a good ide, because I would like to start reading the oldest file and at last the newest. Any ideas?