randy
randy

Reputation: 1

c# directory.getfiles multiple searchpattern

I am trying to use the Directory.GetFiles() method to retrieve a list of files of multiple search pattern

response_201704_1245.1,
response_201704_1245.1.done,
response_201704_1245.12.inpro,
response_201704_1245.450.complete like this.

Is there a way to do this in one call?

Upvotes: 0

Views: 309

Answers (1)

Nino
Nino

Reputation: 7115

I don't think you can do it with single pattern. But, here's one suggestion to solve that:

//regex pattern for a string that ends with dot and one or more digits.
Regex regex = new Regex(@"\.[\d]+$");

//get files, with response*.* pattern and then filter them additionally with regex
var files = Directory.GetFiles(@"c:\temp\resp", "response*.*")
    .Where(d => regex.IsMatch(d))
    .ToList();

Upvotes: 1

Related Questions