?
Solved

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

Posted on 2014-03-05
2
Medium Priority
?
1,191 Views
Last Modified: 2014-03-05
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?
0
Comment
Question by:hankknight
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 42

Assisted Solution

by:sedgwick
sedgwick earned 1000 total points
ID: 39906170
int count = Directory.GetFiles(@"C:\images", "*.png", SearchOption.AllDirectories).Length;

Open in new window

0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 1000 total points
ID: 39906180
Try:
            System.IO.DirectoryInfo dir = new DirectoryInfo("C:\\images");
            int count = dir.GetFiles("*.png", SearchOption.AllDirectories).Count();

Open in new window

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question