Delete files with specific name and creation date

Hi guys,

I want to search a folder for files with a specific name and afterwards delete those files only if the creation date is equal to “today”. Managed to extract the file path by using directory.GetFiles(folderLoc, “ABC*”).

I`m struggling with the if statement: How to check if those files have been created on the day of the bot execution?

Thx!

Hi @n.k2020

1st question for u is that can you give the file name format ?

so using ForEach you will go through the file names one by one

Within ForEach you will use If Activity as shown below :-

item.ToString.Contains(DateTime.Now.ToString(FormatofDateWithInFileName))

Mark as solution and like it if this helps you :slight_smile:

Happy Automation :raised_hands:

Best Regards
Er Pratik Wavhal :robot::man_technologist:t4: :computer:

Thx for your fast reply @Pratik_Wavhal.

It works if I add the date to the file name, unfortunately this is not the case in general.

The files are generated reports which always start with “CC_Analysis_” the following characters are randomly assigned and don`t contain the date. Is there a possibility to check for the date of the download?

BR

Hi @n.k2020

This is for C#.Net

So for that you can use the method as :-

File.GetLastWriteTime(path)

To refer the method visit to below link :-

This is for VB.Net

File.GetCreationTime(path)

To refer the method visit to below link :-

This both will give you creation Date for that particular File

Assign Activity take the particular files Creation Time :-

creationTimeVar = File.GetCreationTime(item)

And Within If Condition you can check both condition using And :-

If
item.ToString.StartsWith(“CC_Analysis_”) And creationTimeVar.Equals(DateTime.Now.ToString(SameDateTimeFormatWhichYouWllGetInAboveVariable))

Mark as solution and like it if this helps you :slight_smile:

Happy Automation :raised_hands:

Best Regards
Er Pratik Wavhal :robot::man_technologist:t4: :computer:

It works! Thx a lot.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.