473,405 Members | 2,176 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

lines count

Is there a mechanism within VS 2005 to determine the number of source code
lines in a C# project (either per file or across the entire project)?

Thanks, Bruce
Nov 17 '05 #1
2 2441
I don't know of one in VS. Here is a quick an dirty console app that will
show you. Compile and put Linecount.exe in a dir in your path. Then just
run LineCount at the console in your project directory.

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace LineCount
{
class Program
{
static int totalCount = 0;

static void Main(string[] args)
{
string path = Environment.CurrentDirectory;
DirectoryInfo di = new DirectoryInfo(path);
Console.WriteLine("Line count for all *.cs files in current
directory and all subdirectories.");
ShowProjectLineCount(di);
Console.WriteLine("Total Project Count: {0}", totalCount);
}

public static void ShowProjectLineCount(DirectoryInfo d)
{
// Curr dir.
FileInfo[] fis = d.GetFiles("*.cs");
foreach ( FileInfo fi in fis )
{
using ( StreamReader sr = fi.OpenText() )
{
string line;
int lineCount = 0;
while ( (line = sr.ReadLine()) != null )
{
lineCount++;
}
totalCount += lineCount;
Console.WriteLine("{0} {1}", lineCount, fi.FullName);
lineCount = 0;
}
}
// Subdirectories.
DirectoryInfo[] dis = d.GetDirectories();
foreach ( DirectoryInfo di in dis )
{
ShowProjectLineCount(di);
}
}
}
}

--
William Stacey [MVP]

"Bruce" <co*********@newsgroup.nospam> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Is there a mechanism within VS 2005 to determine the number of source code
lines in a C# project (either per file or across the entire project)?

Thanks, Bruce

Nov 17 '05 #2
William
Works like a charm. You saved me easily 60+ minutes... if I had tried it
to code it myself.
Thanks,
Bruce

"William Stacey [MVP]" <st*****@mvps.org> wrote in message
news:uF**************@TK2MSFTNGP11.phx.gbl...
I don't know of one in VS. Here is a quick an dirty console app that will
show you. Compile and put Linecount.exe in a dir in your path. Then just
run LineCount at the console in your project directory.

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace LineCount
{
class Program
{
static int totalCount = 0;

static void Main(string[] args)
{
string path = Environment.CurrentDirectory;
DirectoryInfo di = new DirectoryInfo(path);
Console.WriteLine("Line count for all *.cs files in current
directory and all subdirectories.");
ShowProjectLineCount(di);
Console.WriteLine("Total Project Count: {0}", totalCount);
}

public static void ShowProjectLineCount(DirectoryInfo d)
{
// Curr dir.
FileInfo[] fis = d.GetFiles("*.cs");
foreach ( FileInfo fi in fis )
{
using ( StreamReader sr = fi.OpenText() )
{
string line;
int lineCount = 0;
while ( (line = sr.ReadLine()) != null )
{
lineCount++;
}
totalCount += lineCount;
Console.WriteLine("{0} {1}", lineCount, fi.FullName);
lineCount = 0;
}
}
// Subdirectories.
DirectoryInfo[] dis = d.GetDirectories();
foreach ( DirectoryInfo di in dis )
{
ShowProjectLineCount(di);
}
}
}
}

--
William Stacey [MVP]

"Bruce" <co*********@newsgroup.nospam> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Is there a mechanism within VS 2005 to determine the number of source
code lines in a C# project (either per file or across the entire
project)?

Thanks, Bruce


Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
by: Ling Lee | last post by:
Hi all. I'm trying to write a program that: 1) Ask me what file I want to count number of lines in, and then counts the lines and writes the answear out. 2) I made the first part like this: ...
24
by: Joerg Schuster | last post by:
Hello, I am looking for a method to "shuffle" the lines of a large file. I have a corpus of sorted and "uniqed" English sentences that has been produced with (1): (1) sort corpus | uniq >...
1
by: j | last post by:
Hi, I've been trying to do line/character counts on documents that are being uploaded. As well as the "counting" I also have to remove certain sections from the file. So, firstly I was working...
6
by: Samuel Shulman | last post by:
Is there any way to put a limit on the number of lines in a textbox? (appart of number of characters) Thank you, Samuel
6
by: ivan.perak | last post by:
Hello, im a beginner in VB.NET... The thing i would like to do is as it follows.... I have a text file (list of names, every name to the next line) which is about 350000 lines long. I would...
19
by: Pavan | last post by:
Hi, I want to know if there is any software for measuring lines of code of my c++ application. I found out a tool, sloccount, but it gives only physical lines of code. I found out one more...
3
by: Robert | last post by:
I would like to count lines in a file using the fileinput module and I am getting an unusual output. ------------------------------------------------------------------------------...
4
by: creeds | last post by:
Hello !! i have a text file, from where i have to perform an operation such as awk for every lines. i can count the number of lines with cat filename | wc -l , no problem with that. my...
9
by: NvrBst | last post by:
Whats the best way to count the lines? I'm using the following code at the moment: public long GetNumberOfLines(string fileName) { int buffSize = 65536; int streamSize = 65536; long...
1
by: ramprat | last post by:
I am using a Dlookup to pull a value from my traffic table for a record prior to moving that record to a traffic_history table. I want to take the value and store it in a variable and then populate a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.