Link to home
Create AccountLog in
Avatar of Fatehbourghoud

asked on


HI Expert ;

My C# Code have to get the files with pattern  
"SAAA502" + DateTime.Now.ToString("yyyyMMdd") + "_*.CSV"  witch is the file name , I coded that as following but  dont work !!!

following My Code :  

 string fileStore502 = string.Empty;

 string[] filesStore502 = System.IO.Directory.GetFiles(directoryPath, "SAAA502" + DateTime.Now.ToString("yyyyMMdd") + "_*.CSV");

so when I test My code with file SAAA50220101230_231948.CSV My string Array filesStore502 steel empty!!! and the methode didn't get the file using the pattern above

Can you please let me know how to fix that

Thank s
Avatar of nepaluz
Flag of United Kingdom of Great Britain and Northern Ireland image

Your "wildcard" expression here


is causing you the problems.
Avatar of nepaluz
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Where did you get that from? It is a valid expression.

Have you confirmed that the variable "directoryPath" has the path you expect and is properly formatted?

- Anthony
Avatar of Dmitry G
This wildcard is not causing any problems at my computer.

I have a file named: "SAAA50220101231_231948.csv".
I vae the code below. And everything works...
private void button2_Click(object sender, EventArgs e)
            string directoryPath = @"C:\work";
            string[] filesStore502 = System.IO.Directory.GetFiles( directoryPath,  "SAAA502" + DateTime.Now.ToString("yyyyMMdd") + "_*.CSV");
            foreach (string filename in filesStore502)


Open in new window

Exactly my point anarki. Thanks.

My only guess, since there are no errors, is the directoryPath variable.

- Anthony
If path does not exist  - an exception is thrown... But yes, if it's wrong (and still exist) - nothing will be found.
Avatar of Fatehbourghoud


Thanks nepaluz
@ anarki

The nepaluz solution works for me
You are welcome. Glad to help.