How to open the latest excel file within folder?

Hello everyone,

I’m trying to make studioX open the most recent file within a folder - how could I do this using the “Use Excel File” activity? i.e. what should I type in the “Excel file” box?

For example, let’s say that I’m trying to open the most recent file from the following folder:
C:\Users\userone\Apps\Roam\Company\Foldername

Regards

@alberto.lombardi

Use for each file in folder and sort by created date…

Inside that use excel file activity and give currentfile.FullName

After the use excel file activity use a break to end the loop after the first file…so only always latest file is taken

Hope this helps

Cheers

Hi @alberto.lombardi

Can you try the below

Hi @alberto.lombardi

Try the below expression which used to store the path of the latest file in a folder

- Assign -> FolderPath = "Provide the folder path here"

- Assign -> LatestFile = System.IO.Directory.GetFiles(FolderPath, "*.xlsx").OrderByDescending(Function(f) System.IO.File.GetLastWriteTime(f)).FirstOrDefault()

Take Use excel file activity, in the Excel file field provide the LatestFile variable. LatestFile variable contains the latest updated or created excel path.

Note : The FolderPath and LatestFile both variables are Sting datatype variables.

Check the below image for better understanding,

Hope it helps!!

Hi @alberto.lombardi

In StudioX, we can achieve it as the following below process:

Regards

@alberto.lombardi

Try this in the Excel file Field,

Directory.GetFiles(“C:\Users\userone\Apps\Roam\Company\Foldername”, “*.xlsx”)
.OrderByDescending(Function(f) New FileInfo(f).LastWriteTime)
.FirstOrDefault()

Happy Automation!!