0

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?

4
  • Directory.GetFiles(@"c:\temp", "response*.*"); Commented Apr 14, 2017 at 10:37
  • thank you nino.But i don't need response_201704_1245.1.done,response_201704_1245.12.inpro,response_201704_1245.450.complete files and also int value frequently increase Commented Apr 14, 2017 at 10:43
  • so, you want to include only files that end with int extension, and not those with additional extensions (like done, inpro etc)? Commented Apr 14, 2017 at 10:45
  • Yes, you got my point Commented Apr 14, 2017 at 10:47

1 Answer 1

1

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();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.