如何从c#目录中过滤多个文件? [英] How to filter multiple files from a directory in c#?

查看:79
本文介绍了如何从c#目录中过滤多个文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用EC192过滤文件&来自目录的EC292。



目前我的代码如下:



I want to filter files with EC192 & EC292 from a directory.

Currently my code is as below:

string SearchFilePattern = "EC"+MessageType+"*";
                string[] fileList = Directory.GetFiles(COMMON.FPPath, SearchFilePattern);

推荐答案

您可以使用此搜索模式: EC?92 * 。这将返回名称为EC92 *,ECx92 *的所有文件,其中x可以是任何内容。



一旦有了这个列表,就可以使用LINQ表达式过滤掉。这样的事情:



You can make use of this search pattern: EC?92*. This will return all the files with names like EC92*, ECx92* where x could be anything.

Once you have this list, you can filter out using LINQ expression. Something like this:

IEnumerable<string> fileList = Directory.GetFiles("D:\\Test", "EC?92*").Where(x => x.StartsWith("EC1") || x.StartsWith("EC2"));


这篇关于如何从c#目录中过滤多个文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆