Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/tfs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# c directory.getfiles多搜索模式_C#_.net - Fatal编程技术网

C# c 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

我正在尝试使用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 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等)的文件吗?是的,你明白我的意思了