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.

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