class Dirs { public string DirName { get; set; } public long DirSize { get; set; } } static void OrderFiles(string dir) { string[] dirs = Directory.GetDirectories(dir); List<Dirs> dirsList = new List<Dirs>(); foreach (var di in dirs) { try { long dirSize = GetDirSize(di); dirsList.Add(new Dirs() { DirName = di, DirSize = dirSize }); } catch { } } var orderedList = dirsList.OrderByDescending(x => x.DirSize).ToList(); foreach (var orderdir in orderedList) { Console.WriteLine(orderdir.DirName + "," + orderdir.DirSize); } } static long GetDirSize(string dir) { DirectoryInfo dirInfo = new DirectoryInfo(dir); var allFiles = dirInfo.GetFiles("*", SearchOption.AllDirectories).ToList(); long allFilesSize = 0; foreach (var file in allFiles) { allFilesSize += file.Length; } return allFilesSize; }