Reading csv files with dynamic names

Hello,
I need to read csv files with dynamic names every month.
For example,
PayoutSummaryReport_2021-04-01_2021-04-30.csv my current file name.
PayoutSummaryReport will remain same however date will change.
How should I convert to csv with dynamic names into excel?
Any help will be appreciated.

Hi @Basak_Demirel,

Are you trying to save the file every month ?

If yes try this out while saving the file or write CSV

Store this in int let it be variable “days”

System.DateTime.DaysInMonth(Now.tostring(yyyy),now.tostring(MMMM))

“PayoutSummartReport_” + Now.tostring(yyyy-MM-01) + Now.adddays(days).tostring(yyyy-MM-01)

Hope this helps :slight_smile:
If yes, please mark this as solution

This file name has last month’s first date and last month’s last date always right??

Yes it will be

Thank you 8 will try and let you know if it works or not

@Basak_Demirel - Please try like this…

strFirstDayLMOnth = new DateTime(now.Year,now.Month, 1).AddMonths(-1).toString("yyyy-MM-dd")

strLastDayLMonth = new DateTime(now.Year,now.Month, 1).AddDays(-1).toString("yyyy-MM-dd")

To read the last month’s file you can code as

Directory.getfiles ("yourfolderpath", "PayoutSummaryReport_" + strFirstDayLMOnth + "-" + strLastDayLMonth + ".csv")

Sample Workflow with Output

@Basak_Demirel - Did you get a chance to try ?

Thank you so much!!