tags:

views:

36

answers:

1

I am using C#3.0 and dotnet framework 3.5.

Thanks

A: 

You could construct a regex from your basic file name plus (depending on the pattern) sub-regexes.

The sub-regexes could be

 yyyy = @"\d{4}"

(unless you want to restrict a certain year range)

 mm = @"(1[0-2]|0[1-9])"
 dd = @"(3[01]|[12][0-9]|0[1-9])"

Build your regex by adding them in the correct order:

 re = @"\AEUDataFiles" + yyyy + mm + dd + @"\.txt\Z"

Then you can check whether the filename(s) you've found match the regex:

foundMatch = Regex.IsMatch(subjectString, re);

Of course, this isn't a validation for correct dates (20100231 would pass), but that's probably not a problem in this case.

Tim Pietzcker
Yes, but you can read the pattern the user chose, and rearrange the regex accordingly, can't you? If the user chooses DDMMYYYY, then you need to build 're = @"\AEUDataFiles" + dd + mm + yyyy + @"\.txt\Z"'
Tim Pietzcker