G
Guest
I have the following function to get the directory sizse, i wondering if
there any better way to find directory size
public static double GetDirectorySize(string DirectoryPath)
{
double fDirSize = 0 ;
if(!System.IO.Directory.Exists(DirectoryPath))
return fDirSize;
try
{
System.IO.DirectoryInfo dirInfo = new
System.IO.DirectoryInfo(DirectoryPath);
System.IO.FileInfo[] oFiles = dirInfo.GetFiles();
if(oFiles.Length > 0 )
{
int nFileLen = oFiles.Length;
for (int i=0 ; i < nFileLen ; i++)
fDirSize += oFiles.Length ;
}
System.IO.DirectoryInfo[] oDirectories = dirInfo.GetDirectories();
if (oDirectories.Length > 0 )
{
int nDirLen = oDirectories.Length;
for (int i=0 ; i < nDirLen ; i++)
fDirSize += GetDirectorySize(oDirectories.FullName);
}
}
catch(System.Exception ex)
{
throw new System.IO.IOException("GetDirectorySize >>" + ex.Message + ">>" +
ex.StackTrace);
}
return fDirSize ;
}
there any better way to find directory size
public static double GetDirectorySize(string DirectoryPath)
{
double fDirSize = 0 ;
if(!System.IO.Directory.Exists(DirectoryPath))
return fDirSize;
try
{
System.IO.DirectoryInfo dirInfo = new
System.IO.DirectoryInfo(DirectoryPath);
System.IO.FileInfo[] oFiles = dirInfo.GetFiles();
if(oFiles.Length > 0 )
{
int nFileLen = oFiles.Length;
for (int i=0 ; i < nFileLen ; i++)
fDirSize += oFiles.Length ;
}
System.IO.DirectoryInfo[] oDirectories = dirInfo.GetDirectories();
if (oDirectories.Length > 0 )
{
int nDirLen = oDirectories.Length;
for (int i=0 ; i < nDirLen ; i++)
fDirSize += GetDirectorySize(oDirectories.FullName);
}
}
catch(System.Exception ex)
{
throw new System.IO.IOException("GetDirectorySize >>" + ex.Message + ">>" +
ex.StackTrace);
}
return fDirSize ;
}