Click here to Skip to main content
15,924,317 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to filter files with EC192 & EC292 from a directory.

Currently my code is as below:

C#
string SearchFilePattern = "EC"+MessageType+"*";
                string[] fileList = Directory.GetFiles(COMMON.FPPath, SearchFilePattern);
Posted
Comments
Sergey Alexandrovich Kryukov 1-Feb-16 23:23pm    
And?
—SA
PIEBALDconsult 1-Feb-16 23:39pm    
You will likely need to make more than one call. But you can also encapsulate it in a method to hide those details.

1 solution

You can make use of this search pattern: EC?92*. This will return all the files with names like EC92*, ECx92* where x could be anything.

Once you have this list, you can filter out using LINQ expression. Something like this:

C#
IEnumerable<string> fileList = Directory.GetFiles("D:\\Test", "EC?92*").Where(x => x.StartsWith("EC1") || x.StartsWith("EC2"));
 
Share this answer
 
v2
Comments
Mehdi Gholam 2-Feb-16 0:53am    
5'ed
ranio 2-Feb-16 1:49am    
how to get the values from Ienumerbale string list.
I tried looping
foreach(string file in fileList)
{

}
But not working
dan!sh 2-Feb-16 1:53am    
What do you mean by not working? You can iterate IEnumerables using foreach.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900