How to order GetFiles in descending order by date modified

Hi all,

Please could you advise what is the best way to order a directory of files in ascending order to create a list?

We are currently using the following code but would like to order by date modified if possible:

system.IO.Directory.GetFiles(“C:\RPA\Vector Reports”,“IW28*”)

Any help would be much appreciated.

Thanks,
Tony

@TRX

You can use following LINQ query -

Directory.GetFiles(@“C:\RPA\Vector Reports”,“IW28*”).OrderByAscending(d => new FileInfo(d).GetLastWriteTime)

Regards,
Karthik Byggari

check the below link:

1 Like

Just sharing this solution for others.

New DirectoryInfo(dir).GetFiles().OrderByDescending(Function(f) f.LastWriteTime).[Select](Function(f) New FileInfo(f.FullName)).Where(Function(f) f.Extension.Equals(".pdf", StringComparison.OrdinalIgnoreCase)).ToList()