Get latest updated file with same name

Hi,
I have 2 files with same name and I need to take the latest updated file.
How to get that file?
Can anyone let me know?

Hi @Kunal_Jain

The two files with similar name cannot be saved in a folder. How you are taking that files, from one folder or two different folders.

Hi @mkankatala
one file is saved with name copy
but I am using For each file in folder and specified a filter for the initials of file name.
So I need to get the latest file.
How to get that?
Example:-
File names are ABC.xlsx and ABC(copy).xlsx
ABC.xlsx updated time on 01/02/2024
And
ABC(copy).xlsx updated on 01/22/2024
So the bot should pick ABC(copy).xlsx file for further processing.

Okay @Kunal_Jain

In For each file in folder activity there is Order by dropdown, select the Last Updated newest first option then only you will get the file which is newly updated.

Check the below image for better understanding,
image

Hope it helps!!

I have specified it but it is giving both the file names.

Break the loop after the first iteration by using the Break activity. In first iteration you will get the newly updated file name and store in a String Variable. After that assign activity insert the break activity to break the loop.

Check the below image,

Hope it helps!!

Hi @Kunal_Jain,

Syntax : Directory.GetFiles(“Folderpath”).OrderByDescending(Function(a) New FileInfo(a).LastWriteTime ).First

It Helps!

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