C# c directory.getfiles多搜索模式
我正在尝试使用Directory.GetFiles方法检索多个搜索模式的文件列表C# c directory.getfiles多搜索模式,c#,.net,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. 有没有一种方法可以在一次通话中做到这一点?我认为你不能用单一模式做到这一点。但是,这里有一个解决这个问题的建议: //regex pattern for a
response_201704_1245.1,
response_201704_1245.1.done,
response_201704_1245.12.inpro,
response_201704_1245.450.complete like this.
有没有一种方法可以在一次通话中做到这一点?我认为你不能用单一模式做到这一点。但是,这里有一个解决这个问题的建议:
//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();
目录GetFiles@c:\temp,响应*;谢谢你,尼诺。但我不需要response_201704_1245.1。完成,response_201704_1245.12。inpro,response_201704_1245.450。完整的文件和经常增加的int值。所以,你想只包括以int扩展名结尾的文件,而不是那些带有额外扩展名(如done、inpro等)的文件吗?是的,你明白我的意思了