drupal stats

Get Directory Size using C#

August 4th, 2011 File 1 Comment


Directory Size thumb Get Directory Size using C#

 

Get Directory Size using C#

static long GetDirectorySize(string path)

{

    long folderSize = 0;

    string[] files = Directory.GetFiles(path, "*.*", System.IO.SearchOption.AllDirectories);            

    foreach (string file in files)

    {              

        FileInfo info = new FileInfo(file);

        folderSize += info.Length;

    }

    return folderSize;

}

 

Example:

MessageBox.Show("Folder Size: " + GetDirectorySize("D:\\Fonts"));

 

Folder Size thumb Get Directory Size using C#

Tags: c# get folder size, C# get directory size, get directory size c#, get folder size C#, c# directory size, get directory size in c#, get folder size in c#, how to get directory size in c#, c# folder size, how to get the folder size in c#

Related posts:

  1. Get Excel Sheet Names using C#

1 Comment

  1. Joseph says:

    So how would I display just the directory size in a label? Just numbers.