File Matching using wildcards

I'm searching a directory

O:\Data_R\Global\Standard_and_Poors\Equities\Constituents_SnP_Citigroup_2.

Files there include the following:
20150304_SPBMI_GL_BMI_CLS.SDC
20150304_SPBMI_GL_MSI_CLS.SDC
20150304_SPBMI_GL_PROP_CLS.SDC

The first part of the name corresponds to the date.

I want to look at files with this pattern:

O:\Data_R\Global\Standard_and_Poors\Equities\Constituents_SnP_Citigroup_2\*_BMI_*.SDC

In other words I only want to look at the first file in the list.

How do I write some C# code to do this?  I'm using visual studio 2008.
AlHal2Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

KimputerCommented:
this should solve your problem (not full code, just something for you to tinker with):

            string abc = "20150304_SPBMI_GL_BMI_CLS.SDC";
            string pat = @".*_BMI_.*\.SDC$";

            Regex r = new Regex(pat, RegexOptions.IgnoreCase);
            
            Match m = r.Match(abc);

         if ( m.Success ){
             MessageBox.Show("yes");

         }
         else {
             MessageBox.Show("no");
         }

Open in new window


also, requires: using System.Text.RegularExpressions;
0
it_saigeDeveloperCommented:
Which .NET version?

Assuming .NET 4 or above -
using System;
using System.IO;

namespace EE_Q28630718
{
	class Program
	{
		static void Main(string[] args)
		{
			DirectoryInfo dir = new DirectoryInfo(@"O:\Data_R\Global\Standard_and_Poors\Equities\Constituents_SnP_Citigroup_2");
			var files = dir.EnumerateFiles("*_BMI_*.SDC");
			foreach (var file in files)
				Console.WriteLine(file.FullName);
			Console.ReadLine();
		}
	}
}

Open in new window


For prior versions you would use something like -
using System;
using System.IO;

namespace EE_Q28630718
{
	class Program
	{
		static void Main(string[] args)
		{
			DirectoryInfo dir = new DirectoryInfo(@"O:\Data_R\Global\Standard_and_Poors\Equities\Constituents_SnP_Citigroup_2");
			var files = dir.GetFiles("*_BMI_*.SDC");
			foreach (var file in files)
				Console.WriteLine(file.FullName);
			Console.ReadLine();
		}
	}
}

Open in new window

-saige-
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AlHal2Author Commented:
This line is in the config file.
O:\Data_R\Global\Standard_and_Poors\Equities\Constituents_SnP_Citigroup_2\*_BMI_*.SDC
With what should I replace it in order to use the regular expression.

There are lots of similar processes using slightly different SDC files.  I want to use the same code for all of them and cater for the for regular expression in the config file.
0
KimputerCommented:
Using it_saige's solution, it's quite easy:

Read line from config file (O:\Data_R\Global\Standard_and_Poors\Equities\Constituents_SnP_Citigroup_2\*_BMI_*.SDC)

split it up so you get the part after the last slash

use the first part in this line:

DirectoryInfo dir = new DirectoryInfo(@"O:\Data_R\Global\Standard_and_Poors\Equities\Constituents_SnP_Citigroup_2");

use the last part in this line:

var files = dir.EnumerateFiles("*_BMI_*.SDC");

if you use my solution, it's a bit more complicated (depending on your needs and the results of the config file, how many variations are there).
Supply as many results as possible, and I can probably get a function ready.
0
AlHal2Author Commented:
thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.