Find latest File in a folder with respect to date Created

@RishiVC1,

Obviously, if it has yesterday as a lastmodifieddate then if you compare with todays date then it returns an empty array. And if you try accessing it elements, probably you will end up in error.
Solution you can check the count of that array before you access or make any operation.

It should be file.CreationTime .
Reference

  1. How do I get the lastest file in the folder - #2 by vvaidya
  2. FileInfo Class (System.IO) | Microsoft Learn

Regards,
Dom :slight_smile:

1 Like