Open the latest Excel file

Hi,

I have downloaded the latest Excel file that I am going to use via UiPath. Now I have to open this file, but since it is dynamic, and the latest Excel file today might not be the latest file tomorrow, I have to use some kind of function?

I have read that I have to write something like this in Excel application scope.
DirectoryInfo().GetDirectories(“*”,SearchOption.AllDirectories).OrderByDescending(function(d) d.CreationTime).First();

My file location is:C:\Users\kbb\Downloads

Can someone help me with this in details?

Hi @Karsten_Bertelsen

Welcome to uipath community

We can use like this
Out_filepath = Directory.GetFiles(“yourFolderPath”,“*.xlsx”,SearchOption.AllDirectories).OrderByDescending(Function(d) New FileInfo(d).CreationTime).Take(1) )
Where out_filepath a variable of string which will get the last created file from the specified folder

Hope this would help you
Kindly try this and let know for any queries or clarification
Cheers @Karsten_Bertelsen

Thanks for the fast response!

Does this mean that is have to insert this sentence in Excel Application Scope, while replacing “yourFolderPath”?
**Directory.GetFiles(“yourFolderPath”,“*.xlsx”,SearchOption.AllDirectories).OrderByDescending(Function(d) New FileInfo(d).CreationTime).Take(1) )

What should i do with the out_filepath variable?

Yes we can directly mention this in the file path of excel application scope

And if so no need of creating variable out_filepath and it is actually as string variable storing the above expression. Result
Cheers @Karsten_Bertelsen

1 Like

Thanks for the help Palaniyappan.

Seems like the solution to my problem was:

String.Join(“”,Directory.GetFiles(“YourFolderPath”,“*xls”,SearchOption.AllDirectories).OrderByDescending(Function(d) New FileInfo(d).CreationTime).Take(1) )

1 Like

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