Link to home
Start Free TrialLog in
Avatar of DFCRJ
DFCRJFlag for United States of America

asked on

Determing folder size using c#

How can i determine size of a folder in c# once it's been selected by the folderbrowserdialog?

thanks

Avatar of surajguptha
surajguptha
Flag of United States of America image

or more simply like this
long total = 0;
foreach(System.IO.FileInfo file in dirInfo.GetFiles())
total += file.Length;
ASKER CERTIFIED SOLUTION
Avatar of Daniel Junges
Daniel Junges
Flag of Brazil image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of DFCRJ

ASKER

what would be the best way to display it in the app? tried using a label but returns a conversion error.
I
What code did u use to get the conversion error?
Avatar of DFCRJ

ASKER

Sorry -

System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo("C:\\tmp");
long size = getDirSize(dir);

public long getDirSize(System.IO.DirectoryInfo dir)
        {
            long size = 0;
            System.IO.DirectoryInfo[] dirs = dir.GetDirectories();
            System.IO.FileInfo[] files = dir.GetFiles();

            foreach (System.IO.FileInfo fi in files)
                size += fi.Length;

            foreach (System.IO.DirectoryInfo di in dirs)
                size += getDirSize(di);
            return size;
        }
where here are u assigning the long value to a label?
Avatar of DFCRJ

ASKER

System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo("C:\\tmp");
long size = getDirSize(dir);
lblsize = size;

amongst other places as well. I'm learning.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of DFCRJ

ASKER

Oh YEA!!!
Avatar of DFCRJ

ASKER

Thanks to all who hung in there with a beginner