0

I have a path on which files will be dumped randomly on any day. I have a service which will be running daily to check if we have any latest file dumped. File name will be as "AMCR_Handoff_Report_21022021.txt". Date will be mentioned in the file name.

Now I need to fetch the latest file checking the date modified column.

I have this piece of code which gives me all the files along with directory, and then I need to check all the files based on the date part which doesn't makes sense. There should be an easier way to achieve this I guess.

string[] files = System.IO.Directory.GetFiles(amcrNDMPathWithFileName, "AMCAR_Handoff_Report_*", System.IO.SearchOption.TopDirectoryOnly);
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
  • DirectoryInfo.GetFiles then OrderByDescending on LastWriteTime and take the first one – Steve Aug 23 '21 at 13:21
  • Are you looking to do this? https://stackoverflow.com/questions/1179970/how-to-find-the-most-recent-file-in-a-directory-using-net-and-without-looping – WhoAmI Aug 23 '21 at 14:15

0 Answers0