c# - 使用 GetFiles() 时如何排除某些文件
问题描述
我有一个包含 2 个子文件夹的文件夹,每个子文件夹包含大约 1000 个文件。文件如下所示:
38485303_SARA_N211_T.ygx
38485303_SARA_N211_B.ygx
38208001_ULTI_CARTRI.ygx
我想要 3 个单独的数组 - 我已经拥有了 2 个。
Array 1 = all files ending with "_T."
Array 2 = all files ending with "_B."
Array 3 = all files that dont end with _T or _B
这就是我对数组 1 和 2 所拥有的。
files = Directory.GetFiles(folderPath, "*_T.*", SearchOption.AllDirectories);
files = Directory.GetFiles(folderPath, "*_B.*", SearchOption.AllDirectories);
这就是我试图形成数组 3 的结果,但没有成功:
files = Directory.GetFiles(folderPath, ".ygx", SearchOption.AllDirectories).Where(file => !file.EndsWith("_T.ygx") || !file.EndsWith("_B.ygx")).ToArray();
解决方案
我认为这可行。
files = Directory.GetFiles(folderPath, ".ygx", SearchOption.AllDirectories)
.Where(file => !file.EndsWith("_T.ygx") && !file.EndsWith("_B.ygx")).ToArray();
现在您确保文件不以_T.ygx AND ALSO _B.ygx
推荐阅读
- r - 是否可以在 R 中的一次调用中按条件选择一个变量,然后选择其他一些变量?
- r - data.table 中组之间项目的交集
- python - Django self.save() 不更新模型的状态
- html - 将元素定位在两者都在的元素内
- 元素?
- android - 如何确定 Android 10 设备加入的多播组?
- rust - 如何通过特征委托具有非静态参数的异步函数?
- wiremock - Spring Cloud Contract Stub Runner:如何配置 Wiremock 服务器?
- sql - 删除注入 wordpress 数据库的脚本
- google-cloud-platform - 区域丢失后从 Dataflow 恢复 PubSub 确认的消息
- python - 根据日期从数据框中提取值