using System;
using System.IO;
public class ShowDirSize
{
public static long DirSize(DirectoryInfo d)
{
long Size = 0;
// Add file sizes.
FileInfo[] fis = d.GetFiles();
foreach (FileInfo fi in fis)
{
Size += fi.Length;
}
// Add subdirectory sizes.
DirectoryInfo[] dis = d.GetDirectories();
foreach (DirectoryInfo di in dis)
{
Size += DirSize(di);
}
return(Size);
}
public static void Main(string[] args)
{
DirectoryInfo d = new DirectoryInfo("c:\\");
long dsize = DirSize(d);
Console.WriteLine("The size of {0} and its subdirectories is {1} bytes.", d, dsize);
}
}