Is there a quick way, in Visual Studio, to know how many lines of code exist in a project?
6 Answers
In Visual Studio 2008, right click a project and select "Calculate Code Metrics". It includes a few other metrics like cyclomatic complexity. However, it only counts real lines of code, not empty lines or lines with }'s for example.
-
What version(s) of VS2008 is this in? I'm running Professional, and don't see it...– Shog9Feb 23, 2009 at 19:50
-
It is team edition only - on the developer menu. Not that we have it, because like most people we don't use team. Feb 23, 2009 at 20:17
Install cygwin, start a bash shell, cd to the top directory and issue something like:
find . -name "*.cpp" -exec cat {} \; | wc -l
Paul.
-
This ignores .c/.h files, forks a new process for every source file, doesn't give a final total, and counts meaningless lines (blank lines, comments, lines containing only braces, etc.) Feb 23, 2009 at 20:15
-
I generally get the counts for the header files independently; don't care about CPU usage and believe that there are no such things as meaningless lines. Feb 23, 2009 at 21:05
-
You can also do 'find . -name "*cpp" | xargs cat | wc -l', or in zsh (and possibly bash 4) 'wc -l **/*cpp | tail -n1'. How do you do it in windows without visual studio? Mar 19, 2009 at 21:57
-
Install a Unix shell like Cygwin. Or if you have a real sense of fun, install a VM emulator like VirtualBox, and a Linux distro like Debian, share the Windows filesystem into Samba and then hit the sources directly with bash. Mar 21, 2009 at 15:42
I've used SourceMonitor. Works well enough.
See also the answers on: Simple script to count NLOC?
For a more general solution which will give you line counts and many more useful metrics, I can strongly recommend Source Monitor which is free and can be integrated with VS.
I regularly use http://cloc.sourceforge.net/ to obtain code metrics on several languages including C++.