码迷,mamicode.com
首页 > Windows程序 > 详细

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

时间:2020-06-17 12:48:11      阅读:67      评论:0      收藏:0      [点我收藏+]

标签: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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!