Graviton Graviton - 7 months ago 50
C# Question

Exclude certain file extensions when getting files from a directory

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

I tried

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"));