Hi I have many files in a folder. Those files have date and time in the file name in specific format. I need to extract the date from the name and then sort it by date in ascending order.
File Name example :-
format_type_2011-07-12-13-00-12.txt
Earlier I was using by createTime. But now requirement is changed.
var Files = new DirectoryInfo(FileDirectory).GetFiles()
.OrderBy(f => f.CreationTime)
.ToList();
How do i do it? Any help is appreciated.
This should work:
Since your file names (minus the format info) are already in ISO8601 order (year first, then month, then date, etc.) you can just sort based on the string w/o having to convert to a date.