DFCRJ
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
thanks
or more simply like this
long total = 0;
foreach(System.IO.FileInfo file in dirInfo.GetFiles())
total += file.Length;
long total = 0;
foreach(System.IO.FileInfo
total += file.Length;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
what would be the best way to display it in the app? tried using a label but returns a conversion error.
I
I
What code did u use to get the conversion error?
ASKER
Sorry -
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo("C :\\tmp");
long size = getDirSize(dir);
public long getDirSize(System.IO.Direc toryInfo 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;
}
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo("C
long size = getDirSize(dir);
public long getDirSize(System.IO.Direc
{
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?
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.
long size = getDirSize(dir);
lblsize = size;
amongst other places as well. I'm learning.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Oh YEA!!!
ASKER
Thanks to all who hung in there with a beginner
www.codeproject.com/useritems/Directorysize.asp