How to get previous day file from folder based on filename date

Hi Team,

I need to get previous day file from folder based on filename date , filenames below,

xxx_123_102822
yyy_245_102722
zzz_677_102622

102822–oct-28-2022 – this is the format
xxx,yyy,zzz — filename

if i run the bot today , bot need to pick yesterday file only — yyy_245_102722

Please anyone help me for this

Regards,
Raja G

you can get previous day using

Now.AddDays(-1).toString("MMddyy")

e.g. if run today , it will give 102722

so the below line will give yyy_245_102722
"yyy_245_"+Now.AddDays(-1).toString("MMddyy")

Hi @Raja.G

Can you tell us yyy_245 this name will be static?

Try with this expression it will get the yesterdays file

"yyy_245_"+Datetime.Now.AddDays(-1).toString("MMddyy")+".pdf"

".pdf" -> is the sample you add you extension 

To get the previous date

Datetime.Now.AddDays(-1).toString("MMddyy")

Output -> 102722

Regards
Gokul

1 Like

Hi @Raja.G

Check this expression

Directory.GetFiles("Folder Path","*_"+Now.AddDays(-1).ToString("MMddyy")+".Yourfileextension")

You can use this in for each and loop through the files

Hope this Helps

Regards
Sudharsan

1 Like

You can get the previous day then use the switch case there if the day was yesterday they your code should go for yesterday files