Path to the file with the changing part of the name

Hi. Every day I need to open a file with a name in the format: File_today’s date_time (always different).docx. For Example: File_20201009_010815.docx. How do I set the path to these files so that the program doesn’t pay attention to time? That’s all I could do “C:\MyFolder”“yyyyMMdd”)+"_"+… I will be grateful for any help.

Store the path in a variable let’s say filename

Then use string manipulation

Path.GetFilename(filename).SubString(5,8).Equals(Now.ToString(“yyyyMMdd”) this condition check whether the file is in today date or not without considering time

Mark it as solution if you got it


Nived N :robot:
Happy Automation :slight_smile::slight_smile::slight_smile:

@bolbat_evgenia Use Directory.GetFiles() which supports wild cards.

Pattern = "File_" + Date.Now.ToString("yyyyMMdd") + "_*.docx"
FilesArray = Directory.GetFiles("C:\MyFolder", Pattern) 

Then use a For Each activity to loop through the matching files.

See attached file for an example. FindTheFileOfToday.xaml (6.6 KB)

1 Like

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