Search this blog

Monday, June 1, 2009

Get Folder Size - C#

use Following method to get size of a folder,

To invoke this method, you need to pass directoryinfo object of the folder.

using System.IO;

private double DirSize(DirectoryInfo folderdir)

{

double Size = 0;

FileInfo[] files;

//get all files for the current directory

if (folderdir.Exists)

{

files = folderdir.GetFiles("*.*");

//iterate through the directory and print the files

foreach (FileInfo file in files)

{

//get size of the files

Size += Math.Ceiling(file.Length / 1024.0); // size in KB ;

}

}

return Size;

}

No comments:

Post a Comment