Author: target & MSDN Source: msdn
This method comes from the following documentation, there is a problem more help;) MS-help: //ms.netframeworksdkv1.1.netframeworksdkv1.1.chs/cpref/html/frlrfsystemiodirectoryClasstopic.htmms-help: //msdnqtr.2003Feb .2052 / cpref / html / frlrfsystemiodirectoryclasstopic.htmpublic static long DirSize (DirectoryInfo d) {long Size = 0; // Add file sizes.FileInfo [] fis = d.GetFiles (); foreach (FileInfo fi in fis) {Size = FI.LENGTH;} // add subdirectory sizes.directoryInfo [] DIS = D.GetDirectories (); foreach (directoryInfo di in dis) {size = DIRSIZE (DI);} return (size);} Application example: / / The following example calculates the size of a directory // and its subdirectories, if any, and displays the total size // in bytes.using System; using System.IO; public class ShowDirSize {public static long DirSize (DirectoryInfo d) { Long size = 0; // add file sizes.fileinfo [] FIS = D.Getfiles (); foreach (fileInfo fi in fis) {size = fi.length;} // add subdirectory sizz.directoryInfo [] DIS = D .Getdirectories (); foreach (directoryInfo di in dis) {size = DIRSIZE (DI);} return (size);} public stat IC void main (string [] args) {if (args.length! = 1) {console.writeline ("You Must provides a directory argument at the command line.");} else {DirectoryInfo D = New DirectoryInfo (ARGS [ 0]); console.writeline ("The size of {0} and its subdirectories is {1} bytes.", D, DIRSIZE (D));}}}