从目录中获取文件时排除某些文件扩展名 [英] Exclude certain file extensions when getting files from a directory

查看:12
本文介绍了从目录中获取文件时排除某些文件扩展名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在从目录中获取文件时排除某些文件类型?

How to exclude certain file type when getting files from a directory?

我试过了

var files = Directory.GetFiles(jobDir);

不过好像这个功能只能选择你要包含的文件类型,不能排除.

But it seems that this function can only choose the file types you want to include, not exclude.

推荐答案

你应该自己过滤这些文件,你可以这样写:

You should filter these files yourself, you can write something like this:

    var files = Directory.GetFiles(jobDir).Where(name => !name.EndsWith(".xml"));

这篇关于从目录中获取文件时排除某些文件扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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