How to get latest file from folder . safter writing datatable to csv file , need to format the csv file and attach to email. csv file name as filename_currentdatetime.csv

how to get latest file from folder . safter writing datatable to csv file , need to format the csv file and attach to email. csv file name as filename_currentdatetime.csv. any help with VB expression to get latest file based on current datetime is part of the file name?

Hi @r0818 - Please check the below link

@r0818

Check below for your reference

str_filepath = Directory.GetFiles(yourfolder_path,“*.csv”).OrderByDescending(Function(d) New FileInfo(d).CreationTime).Tolist(0)

Hope this may help you

Thanks,
Srini

Hi @r0818

Try this-

Directory.GetFiles(“C:\YourFolderPath”, “*_currentdatetime.csv”)
.OrderByDescending(Function(f) File.GetCreationTime(f))
.FirstOrDefault()