AlHal2
asked on
File Matching using wildcards
I'm searching a directory
O:\Data_R\Global\Standard_ and_Poors\ Equities\C onstituent s_SnP_Citi group_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\C onstituent s_SnP_Citi group_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.
O:\Data_R\Global\Standard_
Files there include the following:
20150304_SPBMI_GL_BMI_CLS.
20150304_SPBMI_GL_MSI_CLS.
20150304_SPBMI_GL_PROP_CLS
The first part of the name corresponds to the date.
I want to look at files with this pattern:
O:\Data_R\Global\Standard_
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This line is in the config file.
O:\Data_R\Global\Standard_ and_Poors\ Equities\C onstituent s_SnP_Citi group_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.
O:\Data_R\Global\Standard_
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.
Using it_saige's solution, it's quite easy:
Read line from config file (O:\Data_R\Global\Standard _and_Poors \Equities\ Constituen ts_SnP_Cit igroup_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\Sta ndard_and_ Poors\Equi ties\Const ituents_Sn P_Citigrou p_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.
Read line from config file (O:\Data_R\Global\Standard
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\
use the last part in this line:
var files = dir.EnumerateFiles("*_BMI_
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.
ASKER
thanks.
Open in new window
also, requires: using System.Text.RegularExpress