Get directory size


April 22, 2009
If you're new to my website, why don't get my latest posts using RSS Feed or by Email.

another tip »

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

Some more useful articles for you

Under Category: C#.NET Code
Article
Leave a Reply