Hi
How can I create a recursive method that counts how many files with a certain file extension, which is in a directory and the directory's sub directories. Exceptions that can be thrown in the search of the file tree should be handled appropriately.
The user of the program should specify the directory in which to start the search and the file extension for the type of files to be included, such as "*. cs. '

Im using windows form application.

Recommended Answers

Using System.IO;


Directory.GetFiles(@"c:\InitialPath", "*.cs", SearchOption.AllDirectories);
Jump to Post

All 2 Replies

Using System.IO;


Directory.GetFiles(@"c:\InitialPath", "*.cs", SearchOption.AllDirectories);

for the count try:
int count =Directory.GetFiles(@"c:\InitialPath", "*.cs", SearchOption.AllDirectories).Length;

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.