How quickly get all files past a certain date from folder?

I have a folder which contains all error files of our system. For reporting purposes I would like to be able to get all files past a certain date. For example, all files from the last two weeks.
Currently i do this:

fileSearchList = Directory.GetFiles(folderPath)
for each f in fileSearchList
     IF: File.GetLastWriteTime(f) > CDate(startingDate)
             Get file

This is slow since it first gets all the files (5000 of them) while i only really need the first (~200). Is there any way to filter with Directory.GetFiles? The filenames do not contain any information regarding it’s date.

@ijanszen - Please try this to get all the files…

 Directory.GetFiles("YourFolderPath").Where(Function(x) New FileInfo(x).LastWriteTime.Date > Cdate("3/15/2021"))

For getting first 200

Directory.GetFiles("DeleteFiles\").Where(Function(x) New FileInfo(x).LastWriteTime.Date > Cdate("3/15/2021")).take(200)

Hope this helps…

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.