<p>I'm converting an old app that records folder sizes on a daily basis. The legacy app uses the Scripting.FileSystemObject library:</p>

<pre><code>Set fso = CreateObject("Scripting.FileSystemObject")
Set folderObject = fso.GetFolder(folder)
size = folderObject.Size
</code></pre>

<p>There isn't an equivalent mechanism on the System.IO.Directory and System.IO.DirectoryInfo classes.</p>

<p>To achieve the same result in .NET do I actually have to recursively walk the whole folder structure keeping a running total of file sizes?</p>

<p>Update: @Jonathon/Ed - thanks....as I thought. I think I'll just reference the Scripting.FileSystemObject COM library. Works just as well even if breaking the .NET purity of my app. It's for an internal reporting app so it's not such a big deal.</p>

Sadly, yes...who knows why.
```
```
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);  
}
```
```
As seen at:
http://msdn.microsoft.com/en-us/library/system.io.directory.aspx