C# list top 20 biggest files via given path

static void ListTop20BiggestFile()
        {
            string str = @"D:\C";
            var files = Directory.GetFiles(str, "*", SearchOption.AllDirectories).OrderByDescending(x => (new FileInfo(x)).Length).Take(20).ToList();
            if(files!=null && files.Any())
            {
                foreach(var file in files)
                {
                    Console.WriteLine(file);
                }
            }

        }

 

posted @ 2020-06-08 14:43  FredGrit  阅读(124)  评论(0编辑  收藏  举报