ASP.NET/C#: Count all .png files in a folder (recursively)

Using ASP.NET/C#, how can I count the total number of files in the "C:\images\" directory and all of its sub-directories that have a .png extension?
LVL 16
Who is Participating?
Carl TawnConnect With a Mentor Systems and Integration DeveloperCommented:
            System.IO.DirectoryInfo dir = new DirectoryInfo("C:\\images");
            int count = dir.GetFiles("*.png", SearchOption.AllDirectories).Count();

Open in new window

Meir RivkinConnect With a Mentor Full stack Software EngineerCommented:
int count = Directory.GetFiles(@"C:\images", "*.png", SearchOption.AllDirectories).Length;

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.