Get the latest file name downloaded -csv file

I am unable to read the latest file name downloaded from C:\Users\info\Downloads. Please help me

Try with this expression ,

new DirectoryInfo(“yourDirectoryPath”).GetFiles().OrderByDescending(Function(f) f.LastWriteTime).First().ToString

This will return the latest file name as a string output

1 Like

Hi @Nithyakavitharan_T

Welcome to UiPath community

Try with this expression and update the file format in the expression

Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)+"\Downloads").[Select](Function(x) New FileInfo(x)).Where(Function(f) f.Extension.Equals(".xls")).OrderByDescending(Function(x) x.LastWriteTime).Take(1).ToArray()(0).ToString

Regards
Gokul

1 Like

Great it works. It retrieves the full path, I need only the file name.

HI @Nithyakavitharan_T

You can try with this expression

Path.GetFileNameWithoutExtension(Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)+"\Downloads").[Select](Function(x) New FileInfo(x)).Where(Function(f) f.Extension.Equals(".xlsx")).OrderByDescending(Function(x) x.LastWriteTime).Take(1).ToArray()(0).ToString)

Regards
Gokul

1 Like

Thank you.
It retrieves the full path, I need only the file name.

@Nithyakavitharan_T

image

1 Like

WOW, it simply worked. Thanks a lot. You saved my time.

1 Like

Kindly clsoe this topic by mark as solved. It will help for other too.

Regards
Gokul