Created
December 13, 2013 14:45
-
-
Save antonijn/7945328 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Collections.Generic; | |
| using System.Linq; | |
| using System.Text; | |
| using System.IO; | |
| namespace linecounter | |
| { | |
| class Program | |
| { | |
| private static int characters = 0; | |
| private static int lines = 0; | |
| private static int files = 0; | |
| private static void dealWithDir(string path, string pat) | |
| { | |
| try | |
| { | |
| foreach (string str in Directory.GetFiles(path, pat)) | |
| { | |
| StreamReader stream = File.OpenText(str); | |
| string line; | |
| while ((line = stream.ReadLine()) != null) | |
| { | |
| ++lines; | |
| characters += line.Length; | |
| } | |
| ++lines; | |
| ++files; | |
| } | |
| foreach (string dir in Directory.GetDirectories(path)) | |
| { | |
| dealWithDir(dir, pat); | |
| } | |
| } | |
| catch | |
| { | |
| } | |
| } | |
| static void Main(string[] args) | |
| { | |
| #if !DEBUG | |
| string path = args[0]; | |
| #else | |
| string path = "../../"; | |
| #endif | |
| dealWithDir(path, "*.cs"); | |
| Console.WriteLine("C#: {0} characters in {1} lines in {2} files", characters, lines, files); | |
| characters = 0; | |
| lines = 0; | |
| files = 0; | |
| dealWithDir(path, "*.cpp"); | |
| Console.WriteLine("C++: {0} characters in {1} lines in {2} files", characters, lines, files); | |
| characters = 0; | |
| lines = 0; | |
| files = 0; | |
| dealWithDir(path, "*.h"); | |
| Console.WriteLine("Header: {0} characters in {1} lines in {2} files", characters, lines, files); | |
| characters = 0; | |
| lines = 0; | |
| files = 0; | |
| dealWithDir(path, "*.c"); | |
| Console.WriteLine("C: {0} characters in {1} lines in {2} files", characters, lines, files); | |
| Console.ReadKey(); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment