views:

577

answers:

5

Is there a quick way, in Visual Studio, to know how many lines of code exist in a project?

+1  A: 

You could always use the line counter add-in from the sample code.

Jekke
+1  A: 

I've used SourceMonitor. Works well enough.

See also the answers on: Simple script to count NLOC?

Shog9
+3  A: 

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.

Paul Stovell
What version(s) of VS2008 is this in? I'm running Professional, and don't see it...
Shog9
Might be a team edition thing
Paul Stovell
It is team edition only - on the developer menu. Not that we have it, because like most people we don't use team.
Bob Moore
A: 

Install cygwin, start a bash shell, cd to the top directory and issue something like:

find . -name "*.cpp" -exec cat {} \; | wc -l

Paul.

Paul W Homer
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.)
Adam Rosenfield
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.
Paul W Homer
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?
Jonas Kölker
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.
Paul W Homer
+1  A: 

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.

anon