using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace GetFolderSize { class Program { static void Main(string[] args) { FolderNodes a = new FolderNodes(@"D:\Perl64"); ListFolderNode(a, 5); } static void ListFolderNode(FolderNodes fn, int maxLevel) { print(); treeWalk(fn, maxLevel); } static void treeWalk(FolderNodes fn, int maxLevel) { if (fn.deepLevel <= maxLevel) { StringBuilder sb = new StringBuilder(); FolderNodes[] fns = fn.subFolders; sb.Clear(); sb.Append('\t', fn.deepLevel); sb.Append(fn.path); print(fn.totalFileCount, fn.totalFolderCount, fn.totalFolderSize, fn.deepLevel, sb.ToString()); if (fns != null) { for (int idx = 0; idx < fns.Length; idx++) { treeWalk(fns[idx], maxLevel); } } } } static void print() { Console.WriteLine(" files\t folders\t size\t level\t folderName"); } static void print(long files, long folders, long size, int nestLevel, string folderName) { Console.WriteLine("{0:#,##0}\t{1:#,##0}\t{2:#,##0}\t{3}\t{4}", files, folders, size, nestLevel, folderName); } } }