DirectoryInfo.GetDirectories()
using System; using System.IO; public class DirectoryCounter { public static void Main() { DirectoryInfo myDir = new DirectoryInfo(@"c:\Program Files"); int total = CountDirectories(myDir); Console.WriteLine(total); } public static int CountDirectories(DirectoryInfo dir) { DirectoryInfo[] dirs = dir.GetDirectories(); int count = dirs.Length; foreach (DirectoryInfo subDir in dirs) { count += CountDirectories(subDir); } return count; } }