I’m generating invoice CSV Files every month which include the Date(YYYY,MM) in it’s name Monatsrechnung_201911_123456.csv. There can be multiple ones, but all include the date.
How do I grab all of them and attach them to an email/move them to a certain folder?I have the relevant Date already assigned to a variable
You can use the Directory.GetFiles() method in an assign to return all filenames as an array of string. It allows you to use a searchpattern as well, see the documentation here: Directory.GetFiles Method (System.IO) | Microsoft Learn
In your case you could create a string array variable called MyFiles and in an assign activity put the following: Assign MyFiles = Directory.GetFiles(YourDirectoryToSearch,"*_" + YourDateVariable.ToString("yyyyMM") + "_*.csv")
This would grab all files in the directory that have the underscore followed by the date in yyyyMM format, followed by an underscore, and ending in .csv. If you want to search subdirectories, you should include that as a search option.
Now you can iterate through the array of filenames to move them into the folder of your choosing with the ‘move file’ activity. If you need to attach all the files to an email, that is a bit more difficult but you can do it by creating a Mail object and adding all the files using the Mail.attachments.add method. See details here: Option to attach array (string) in send mail for attachment - #9 by Sachin_Desai