DirectoryInfo.GetDirectories() : DirectoryInfo « System.IO « C# / C Sharp by API






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;
    }
}

   
    
  








Related examples in the same category

1.new DirectoryInfo(String path)
2.DirectoryInfo.CreateSubdirectory
3.DirectoryInfo.CreationTime
4.DirectoryInfo.Exists
5.DirectoryInfo.FullName
6.DirectoryInfo.GetFiles()
7.DirectoryInfo.GetFiles(String filter)
8.DirectoryInfo.LastAccessTime
9.DirectoryInfo.LastWriteTime
10.DirectoryInfo.Name
11.DirectoryInfo.Parent