Solved

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

Posted on 2014-03-05
2
1,078 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

895 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now