Home > Net >  Statistical folder file size
Statistical folder file size

Time:12-08

///& lt; Summary> 
The size of the///get a folder
///& lt;/summary>
///& lt; Param name="dir" & gt; Folder directory & lt;/param>
///& lt; Param name="dirSize & gt;" The folder size & lt;/param>
Public static void GetDirSizeByPath (string dir, ref long dirSize)
{
Try
{
DirectoryInfo dirInfo=new DirectoryInfo (dir);

DirectoryInfo [] dirs=dirInfo. GetDirectories ();
The FileInfo files []=dirInfo. GetFiles ();

The foreach (var item in dirs)
{
GetDirSizeByPath (item. FullName, ref dirSize);
}

The foreach (var item in files)
{
DirSize +=item. Length;
}
}
The catch (Exception ex)
{
Console. WriteLine (" failed to get the file size "+ ex. Message);
}

}


An example of online, please give an example of using

Folder directory path: UE/UPLOAD
  • Related