How to get latest file from a folder based on the file name

Hi all,

I have a situation where i have to pick the latest file from a folder . By latest file i mean to say that file present in the folder is appended with timestamp. so, i have to pick the latest file based on the file name.
Note : This folder will contain file with same name but timestamp appended to file are different. So i have to pick latest among them.

Please help…

Regards,
Ahtesham

Hey @md.ahtesham

You can check existing thread to get Reference and let me know in case of problem-

https://forum.uipath.com/t/retrieve-each-file-in-directory-last-modified/

DirectoryInfo directory = new DirectoryInfo("D:\\SampleDirectory");
String LatestFile = directory.GetFiles().OrderByDescending(function(f) f.LastWriteTime).FirstOrDefault()

Regards…!!
Aksh

3 Likes

Here is a detailed article on that :slightly_smiling_face: