Check file in path with specific format name

Hi, Everyone
How to check file in path has format “XXX_YYYYMMDD_Report.xls”
In my loop checking

File as string{}
File = Directory.GetFiles(“PathFile”,“*_Report.xls”, SearchOption.AllDirectories)

PathFile has
yyy_12345678_Report.xls —> I don’t want this file.

Can I check pattern “YYYYMMDD” in file name? Please suggest.

Thank you in advance.

Hi Supakinee_Navawong_na_ayu,

Based on my knowledge i am providing suggestion below. just check if it is useful to you.

i think we cannot directly give YYYYMMDD in search criteria.

you are checking all the files with the format of YYYYMMDD right. try to get the current year and current month dynamically from the functions like Current Year - now.toString(“YYYY”).tostring and current Month - Now.tostring(“MM”).tostring. and pass it to your search criteria like below.

ile = Directory.GetFiles(“PathFile”,CurrentYear+CurrentMonth+“*_Report.xls”, SearchOption.AllDirectories) some thing like this it should work and take correct files and ignore the rest of ones.


Hi @Supakinee_Navawong_na_ayu ,

Please check the Date Examples section from our colleague megapost

Might help you, not only for this issue :slight_smile:

Best regards,


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