c#directory.getfiles多个searchpattern

时间:2017-04-14 10:30:53

标签: c# .net

我正在尝试使用Directory.GetFiles()方法检索多个搜索模式的文件列表

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

有没有办法在一次通话中这样做?

1 个答案:

答案 0 :(得分:1)

我认为你不能用单一模式做到这一点。但是,这是解决这个问题的一个建议:

//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();