Windows Phone Developers

Saturday, November 15, 2008

Get Size of a Particular Directory using C# (.NET)

Get Directory Size using C#

One way to find the size of entire directory (including all sub-directories) is to sum up the size of all files in those directories

The following code snippet adds the size of all the files to get the directory size

private static void GetDirSize(string rootdir)




long DirSize = 0;

DirectoryInfo[] DI = new DirectoryInfo(rootdir).GetDirectories("*.*", SearchOption.AllDirectories);

FileInfo[] FI = new DirectoryInfo(rootdir).GetFiles("*.*", SearchOption.AllDirectories);

foreach (FileInfo F1 in FI)


DirSize += F1.Length;


Console.WriteLine("Total Size of {0} is {1} bytes", rootdir, DirSize);


catch (DirectoryNotFoundException dEX)


Console.WriteLine("Directory Not Found " + dEX.Message);


catch (Exception ex)





Get Directory Size using C#, Get SubDirectory Size using C#, SearchOption.AllDirectories in C#, How to Search All Directories using C#, FileSize using C#, How to get directory size using C#

Get Directory Size using .NET, Get SubDirectory Size using .NET, SearchOption.AllDirectories in .NET, How to Search All Directories using .NET, FileSize using .NET, How to get directory size using .NET

Directory Size using C#

Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon

No comments:

Post a Comment