Regular Expression to replace a pattern at runtime(C#3.0)

Posted by deepak.kumar.goyal on Stack Overflow See other posts from Stack Overflow or by deepak.kumar.goyal
Published on 2010-05-02T19:16:57Z Indexed on 2010/05/02 19:48 UTC
Read the original article Hit count: 250

Filed under:

I have a requirement.

I have some files in a folder among which some file names looks like say

**EUDataFiles20100503.txt, MigrateFiles20101006.txt.**

Basically these are the files that I need to work upon.

Now I have a config file where it is mentioned as the file pattern type as

EUDataFilesYYYYMMDD, MigrateFilesYYYYMMDD.

Basically the idea is that, the user can configure the file pattern and based on the pattern mentioned, I need to search for those files that are present in the folder.

i.e. at runtime the YYYYMMDD will get replaced by the Year Month and Date Values. It does not matter what dates will be there(but not with time stamp ; only dates)).

And the EUDataFiles or MigrateFiles names will be there.(they are fixed)

i.e. If the folder has a file name as EUDataFile20100504.txt(i.e. Year 2010, Month 05, Day 04) , I should ignore this file as it is not EUDataFiles20100504.txt (kindly note that the name is plural - File(s) and not file for which the system will ignore the file).

Similarly, if the Pattern given as EUDataFilesYYYYMMDD and if the file present is of type EUDataFilesYYYYDDMM then also the system should ignore.

How can I solve this problem? Is it doable using regular expression(Replacing the pattern at runtime)?

If so can anyone be good enough in helping me out?

I am using C#3.0 and dotnet framework 3.5.

Thanks

© Stack Overflow or respective owner

Related posts about c#3.0