Get directory size
April 22, 2009
Twitter's a new exciting social media. And guess what, I'm quite active on it. Follow me on Twitter to get the latest links and updates.
Using trace back to get the size of a specific directory.
public long getDirSize(System.IO.DirectoryInfo dir)
{
long size = 0;
System.IO.DirectoryInfo[] dirs = dir.GetDirectories();
System.IO.FileInfo[] files = dir.GetFiles();
foreach (System.IO.FileInfo fi in files)
size += fi.Length;
foreach (System.IO.DirectoryInfo di in dirs)
size += getDirSize(di);
return size;
}

Leave a Reply