Automation to download a file and add it to a monthly excel. I need ui path to look at the folder, find the current months excel and open it. I can get it to choose a specific file i select, but i want it to open the most recent… how do i do it?
Hey @alex.washburn !! Do you want the most recent created or modified?
Let’s create two variables of type String. One for the path of the folder and another for the name of the files we are going to get. In my case I will fetch the most recent file on my Desktop.
To get the latest file we will use:
Directory.GetFiles(str_folder,”*.xl*”).OrderByDescending(Function(d) New FileInfo(d).CreationTime).Take(1)(0)
Hope it helps!!
Directory.GetFiles(str_folder,”*”).Where(Function (a) (new FileInfo(a).CreationTime.month = Now.AddMonths(-1).Month) and (new FileInfo(a).CreationTime.year = Now.AddMonths(-1).year)).OrderByDescending(Function(d) New FileInfo(d).CreationTime).Take(1)(0)
i am absolutely lost on the first one. I have just been using the activities and recording thing in studio x. How do I create a variable?