C# read and compute the code lines number of cs files based on given directory

2021-01-07 15:32

阅读:701

标签:foreach   work   cto   get   contents   sed   str   static   files   

 static void ComputeCodeLines()
        {
            string dir = @"D:\Work";
            int totalLines = 0;
            string[] allFiles = Directory.GetFiles(dir, "*.cs", SearchOption.AllDirectories);
            if(allFiles!=null && allFiles.Any())
            {
                foreach(var file in allFiles)
                {
                    string[] contents = File.ReadAllLines(file);
                    totalLines += contents.Length;
                }
            }
            Console.WriteLine(totalLines);
        }

 

C# read and compute the code lines number of cs files based on given directory

标签:foreach   work   cto   get   contents   sed   str   static   files   

原文地址:https://www.cnblogs.com/Fred1987/p/13151781.html


评论


亲,登录后才可以留言!