How to fetch recent excel file from folder

folder path : C:\Users\A454946\OneDrive \x 2024 templates
Excel file name: xyz.xlsm
there are multiple excel files in given folder path .How to fetch recent excel file using VB expression or any function using assign activity.

Hi @Priti_Patil

Try this:

Directory.GetFiles("C:\Users\A454946\OneDrive\x 2024 templates", "*.xlsm").OrderByDescending(Function(f) New FileInfo(f).LastWriteTime).First()

Regards

Have a look at this

When I am running same function, I get output Properly with different flowchart. but I run from main sequence file , I am getting file name “desktop.inn” . is there any specific Reason?

Try this method once, Change the extension as per your requirement, below code will work for .xlsx and .xls
Directory.GetFiles(“YourFolderPath”, “.xlsx")
.Concat(Directory.GetFiles(“YourFolderPath”, "
.xls”))
.OrderByDescending(Function(f) New FileInfo(f).CreationTime)
.FirstOrDefault()

Hey @Priti_Patil
try this:
allExcelFiles = Directory.GetFiles("C:\Users\A454946\OneDrive\x 2024 templates", "*.xlsm")

recentExcel = allExcelFiles.OrderByDescending(Function(file) New FileInfo(file).LastWriteTime).FirstOrDefault()

allExcelFiles type String
recentExcel type String

–use a assign activity and mention like this
out_filepath = Directory.GetFiles(“yourfilepath”,“*.xlsx”).OrderByDescending(Function(d) New FileInfo(d).CreationTime).ToList(0)