How to get the latest file in a folder

Hi People,

I am trying to get the latest file in a directory… i declared a variable and assigned it to a folder as below:
folderName = new DirectoryInfo("\Mac\Home\Documents\UiPath\folderpath")
The folderName is stored as
I also declared and assigned a filename = folderName…GetFiles().OrderByDescending(f => f.LastWriteTime).First() . The filename is stored as but i am still getting the error “compiler error encountered processing expression”

What could i be doing wrong?
Thank you

Hi @Olaoluwa,

Refer this post


1 Like

This worked for getting the first file. Is there a way to tweak this to get he second or third most recent file. When i chnge it to “Take(2)” it takes both the files

1 Like