How to select/get only yesterday files from folder

Hello Friends,

I have one folder containing multiple excel file’s in that I only wanted to select files that were added yesterday
Note: Excel Filename does not have a date. Like below e.g.
Any input will be appreciable
thanks

1 Like

Hi @Bot_Learner
You can create an array variable and run the following command.

Directory.GetFiles("C:\Users\tainan\Downloads\").Where(Function(d) New FileInfo(d).CreationTime >= Now.AddDays(-1)).ToArray

1 Like

Hi @Bot_Learner

If you want to find all the files that were modified in the last 24 hours you can use a StudioX activity to loop through each file and then use the LastModifiedDate method to find the data they were modified.

First, you will need to click Show StudioX activities in the Activities window filter.

enter image description here

If you want to find all the files that were modified in the last 24 hours you can use a StudioX activity to loop through each file and then use the LastModifiedDate method to find the data they were modified.

Then, select the For Each File in Folder activity.

enter image description here

After that, use this formula in the If activity: Convert.ToDateTime(CurrentFile.LastModifiedDate()) > Now.AddDays(-1)

The name of any file that was modified in the last 24 hours will show up in a Logs.You can add to the “Add to collection” Activity if you require.

Please find the attached xaml.
Files.xaml (7.3 KB)

Thanks.

arrFilesFI  = new DirectoryInfo("C:\").GetFiles().Where(Function (x) x.CreationTime.Date = Now.AddDays(-1).Date).toArray

arrFilesFI | Datatype: FileInfo() - Array of FileInfo

Taken from:

1 Like

Hi @Bot_Learner

You might achieve your goal by adapting the following to your needs:

Assign (String)
yesterday = DateTime.Now.AddDays(-1).ToString("dd-MM-yyyy")

Assign (Array of String)
files = Directory.GetFiles(myDirectory, "*" & yesterday & "*")

If
files.Length = 1

  • Assign (String)
    result = files(0)

Regards
Gokul