public static long DirSize(System.IO.DirectoryInfo d) { long Size = 0; // 所有文件大小. System.IO.FileInfo[] fis = d.GetFiles(); foreach (System.IO.FileInfo fi in fis) { Size += fi.Length; } // 遍历出当前目录的所有文件夹. System.IO.DirectoryInfo[] dis = d.GetDirectories(); foreach (System.IO.DirectoryInfo di in dis) { Size += DirSize(di); } return(Size); }