Graviton Graviton - 10 days ago 7
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.

Answer

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

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