Solved

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

Posted on 2014-03-05
2
1,096 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
2 Comments
 
LVL 42

Assisted Solution

by:sedgwick
sedgwick earned 250 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 250 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Media.Imaging 1 18
VB.NET - Error - Object not set in Module 4 35
Need to learn more about SecurityProtocolType.Tls12 3 32
Convert datetime to time string 10 22
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

825 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