How to check the File that have a date?

Hi,

I have a file (e.g: Data_20231120) and it several file name in a folder( some of files have a date some of them didn’t have). I need to check for both condition, where it contains “Data” and the “date” with the format yyyyMMdd.

I can check the file with only have file name keywords “Data” but when I want to combine with the date it give the current date as it today. So it make my checking file down to false.

So how I want to grab the file that have both condition. I use double “IF” activities. First “IF” to check the filename which is “Data” and second "IF activities to check the date.

Thank you :slight_smile:

@tmiqmal

Does the file name has current date always? Or do you need to check for any date?

If current date use the below to check

Str_Name.Contains("Data_" + Now.ToString("yyyyMMdd"))

Cheers

No. need to check for any date. Past until current. as long as the file have the date

Thank you

Hi @tmiqmal
Try this

FileNmae="Data_20231120"
If
   FilName.Contains("Data_"+ Now.ToString("yyyyMMdd")
Then 
     //Do required process
Else
   //Do required process 
End If

Hope it helps

@tmiqmal

Then try this regex in the if condition

System.Text.RegularExpressions.Regex.IsMatch(str_name,"Data_\d{8}")

Cheers

You need all the files whose name starts with Data (with date & without) right?
You can use below mentioned query in assign activity

Directory.GetFiles(“C:\Users\SM092202\Ajay Mishra\UiPath - Courses”,“Data*.txt”)

Summary: Directory.GetFiles(“path of the folder in which all the files are stored”,“initial name of file+*+Extension of the file(If required)”)

Please find attached a screenshot…!

Thankyou.