Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exclude a file extension in System.IO.Directory.GetFiles()

Tags:

c#

.net

asp.net

Is there a way to get a file count in a folder, but I want to exclude files with extension jpg?

Directory.GetFiles("c:\\Temp\\").Count();
like image 392
jinsungy Avatar asked Jan 28 '11 19:01

jinsungy


2 Answers

Try this:

var count = System.IO.Directory.GetFiles(@"c:\\Temp\\")
                               .Count(p => Path.GetExtension(p) != ".jpg");

Good luck!

like image 161
Homam Avatar answered Oct 26 '22 02:10

Homam


You can use a DirectoryInfo object on the directory, and do a GetFiles() on it with a filter.

like image 26
Mark Avenius Avatar answered Oct 26 '22 02:10

Mark Avenius