How to get the future dated file

Hi, I have a folder with many files, in which there will be only one future dated excel file.
for example the file name is:“Garenswide Riepscde ABCDE-09-20-2021.xlsx”. Now I have to select this file, how can I do that.

1 Like

Hi

Hope these steps would help you resolve this

—use a assign activity like this

arr_filepaths = Directory.GetFiles(“Yourfolderpath”,"*.xlsx",SearchOption.AllDirectories)

This will have all the file path

Now use another assign activity like this

filter_filepaths = arr_filepaths.AsEnumerable().Where(Function(a) a.ToString.Contains(Datetime.Now.AddDays(1).ToString(“MM-dd-yyyy”)).ToList()

Where filter_filepath is a variable of type
System.Collections.Generic.List(of string) which will have only the values you needed

Cheers @nagini.pragna

1 Like

Hi, Thanks for the reply. I am facing issue in this line of code
filter_filepaths = arr_filepaths.AsEnumerable().Where(Function(a) a.ToString.Contains(Datetime.Now.AddDays(1).ToString(“MM-dd-yyyy”)).ToList()

May I know what error you are getting
@nagini.pragna

List(0) { }. I think this is giving the empty list

Today’s date is 14th , and I see the sample file you gave is 20th of this month…So will have any date after today’s date or will it be only Sep file(ie. 14th to 30th)??

Please clarify.

The date will be between 14 to 30

Below query will get the files greater than today’s date and with in this month…

  Directory.GetFiles("YourFolderName","*.xlsx").where(function(x) cdate(right(path.GetFileNameWithoutExtension(x),10)) > now.date and cdate(right(path.GetFileNameWithoutExtension(x),10)).Month.Equals(now.Month)).ToArray

For a test, I have placed a file with 09-20 date, and it picked the files…

Note: Please assign the above code to a stringArray variable. OR if there will be only one file always then you can use the below code and assign it to string variable…

 Directory.GetFiles("YourFolderName","*.xlsx").where(function(x) cdate(right(path.GetFileNameWithoutExtension(x),10)) > now.date and cdate(right(path.GetFileNameWithoutExtension(x),10)).Month.Equals(now.Month))(0)
1 Like

@nagini.pragna - Were you able to solve it??