Q:

How to calculate/determine Folder Size in .NET?

I am creating application in Winform which among other things will also need to have the ability to calculate size of the folder.
Can someone give me pointers how to do that?
thanks

A:

I use the following extension method to do that:
    public static long Size(this DirectoryInfo Directory, bool Recursive = false)
    {
        if (Directory == null)
            throw new ArgumentNullException("Directory");
        return Directory.EnumerateFiles("*", Recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly).Sum(x => x.Length);
    }

