Application Kata "LOC Count"

Develop an application that determines the Lines of Code (LOC) of the source code files in a directory tree. The directory where the search should start is specified as a parameter on the command line. It will be searched from there including the subdirectories. It is up to you to decide which programming language you want to use for the program. In the following example we searched for .cs files (C#). Translated with www.DeepL.com/Translator (free version)

Application example:

c:\> loccount.exe d:\myproject
d:\myproject\Program.cs 10 8
d:\myproject\source\main.cs 156 128
d:\myproject\source\logic.cs 683 542
d:\myproject\source\adapters\db.cs 342 329
d:\myproject\source\adapters\twitter.cs 125 87

Total:
  Lines: 1,316
  LOC: 1,094

For each file, the fully qualified file name, the number of lines in the file, and the lines of code are displayed. In addition, a total sum is displayed under the listing of the individual files.

The following lines are not counted as a line of code:

  • Blank lines (incl. whitespace)
  • Simple comments
    • in the C languages (Java, C#, etc.), lines beginning with "//".
    • in other languages "#"

Choose the comment characters according to the language the program is working with. For example, if you are looking for .cs files, use "//" as the comment character. For .py it would be "#". Note that the comment can be preceded by whitespace.

 

en_USEnglish