I tried rake stats
but that seems highly inaccurate. Perhaps it ignores several directories?
The wc command is used to find the number of lines, characters, words, and bytes of a file. To find the number of lines using wc, we add the -l option. This will give us the total number of lines and the name of the file.
Cloc can be used to count lines in particular file or in multiple files within directory. To use cloc simply type cloc followed by the file or directory which you wish to examine. Now lets run cloc on it. As you can see it counted the number of files, blank lines, comments and lines of code.
Use readlines() to get Line Count This is the most straightforward way to count the number of lines in a text file in Python. The readlines() method reads all lines from a file and stores it in a list. Next, use the len() function to find the length of the list which is nothing but total lines present in a file.
I use the free Perl script cloc. Sample usage:
phrogz$ cloc . 180 text files. 180 unique files. 77 files ignored. http://cloc.sourceforge.net v 1.56 T=1.0 s (104.0 files/s, 19619.0 lines/s) ------------------------------------------------------------------------------- Language files blank comment code ------------------------------------------------------------------------------- Javascript 29 1774 1338 10456 Ruby 61 577 185 4055 CSS 10 118 133 783 HTML 1 13 3 140 DOS Batch 2 6 0 19 Bourne Shell 1 4 0 15 ------------------------------------------------------------------------------- SUM: 104 2492 1659 15468 -------------------------------------------------------------------------------
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With