473,385 Members | 1,275 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,385 software developers and data experts.

Counting code lines i asp.net project

Hi

We have a rather large asp.net project with serveral utility projects
(written in C#). Is there at tool out there which can give an estimate of
the total amount of code lines all projects results in?

thanks in regads
Anders
Nov 19 '05 #1
5 1172
I’d suggest using DPack from USysWare (http://www.usysware.com/dpack/) for
this task. With it installed, it adds a few extra items to your Tools menu
including one named ‘Solution Statistics’ which runs through all of the files
and projects that are part of your solution and lists for you to total number
of lines within, as well as how many of those lines are empty, comments or
code.

Brendan
"Anders K. Jacobsen [DK]" wrote:
Hi

We have a rather large asp.net project with serveral utility projects
(written in C#). Is there at tool out there which can give an estimate of
the total amount of code lines all projects results in?

thanks in regads
Anders

Nov 19 '05 #2
At the end of this post is a C# program I had to count all lines of code in a
single directory tree. Not exactly what you had in mind, but you could parse
through the solution files to find the particular projects you are interested
in.

I have thought about going back through the code and making a Visual Studio
add in, but I am wracked at this time. I am sure there are code metric tools
that are far better than this.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
"Anders K. Jacobsen [DK]" wrote:
Hi

We have a rather large asp.net project with serveral utility projects
(written in C#). Is there at tool out there which can give an estimate of
the total amount of code lines all projects results in?

thanks in regads
Anders


/* CODE SAMPLE ******************************************/
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;

namespace LineCounter
{
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button btnRun;
private System.Windows.Forms.TextBox txtDirectory;
private System.ComponentModel.Container components = null;

public Form1()
{
InitializeComponent();
}

protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
private void InitializeComponent()
{
this.btnRun = new System.Windows.Forms.Button();
this.txtDirectory = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// btnRun
//
this.btnRun.Location = new System.Drawing.Point(8, 40);
this.btnRun.Name = "btnRun";
this.btnRun.TabIndex = 0;
this.btnRun.Text = "Run";
this.btnRun.Click += new System.EventHandler(this.btnRun_Click);
//
// txtDirectory
//
this.txtDirectory.Location = new System.Drawing.Point(8, 8);
this.txtDirectory.Name = "txtDirectory";
this.txtDirectory.Size = new System.Drawing.Size(256, 20);
this.txtDirectory.TabIndex = 1;
this.txtDirectory.Text = "C:\\Projects\\SOURCE_SAFE\\Code\\AIMHealth";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.txtDirectory);
this.Controls.Add(this.btnRun);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);

}
#endregion

[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private long _totalCount=0;
StreamWriter _sw = new StreamWriter(@"C:\temp\counts.txt");
private char[] _split = { '\\' };

private void btnRun_Click(object sender, System.EventArgs e)
{
_totalCount=0;

//Write out header
_sw.WriteLine("Directory|File|File Line Count|Directory Line Count");

//Get the starting directory
string startDir = txtDirectory.Text;
//startDir = @"C:\Projects\Temp\DataTest\DataTest";

//Set up the total count
_totalCount += GetLinesForDirectory(startDir);

//Write out footer
_sw.WriteLine("TOTAL||||"+_totalCount.ToString());
_sw.Flush();
_sw.Close();

MessageBox.Show(_totalCount.ToString());
}

private long GetLinesForDirectory(string directoryPath)
{
DirectoryInfo di = new DirectoryInfo(directoryPath);
long directoryCount = 0;

//Directories
foreach(DirectoryInfo d in di.GetDirectories())
{
_totalCount += GetLinesForDirectory(d.FullName);
}

//Files
foreach(FileInfo f in di.GetFiles())
{
if((f.Extension==".cs")||(f.Extension==".asax")||( f.Extension==".aspx")||(f.Extension==".asmx")||(f. Extension==".ascx"))
directoryCount += GetLinesForFile(f.FullName, directoryPath);
}

//Write out the line
if(directoryCount!=0)
{
_sw.WriteLine(directoryPath+"|||"+directoryCount.T oString());
}

return directoryCount;
}

private long GetLinesForFile(string filePath, string directoryPath)
{
long counter=0;
string line;
StreamReader sr = new StreamReader(filePath);
string[] fileBroken = null;

while(sr.Peek()>=0)
{
line=sr.ReadLine().Trim();

if(line.Length>0)
{
if((line.Substring(0,1)!=@"/")&&(line.Substring(0,1)!=@"*")&&(line.Substring(0 ,1)!=@"#"))
counter++;
}
}

if(counter!=0)
{
fileBroken = filePath.Split(_split);

_sw.WriteLine(directoryPath+"|"+fileBroken[fileBroken.Length-1]+"|"+counter.ToString());
}

return counter;
}
}
}

Nov 19 '05 #3
PErfect !
"Brendan Grant" <gr****@NOSPAMdahat.com> skrev i en meddelelse
news:44**********************************@microsof t.com...
I'd suggest using DPack from USysWare (http://www.usysware.com/dpack/) for
this task. With it installed, it adds a few extra items to your Tools menu
including one named 'Solution Statistics' which runs through all of the
files
and projects that are part of your solution and lists for you to total
number
of lines within, as well as how many of those lines are empty, comments or
code.

Brendan
"Anders K. Jacobsen [DK]" wrote:
Hi

We have a rather large asp.net project with serveral utility projects
(written in C#). Is there at tool out there which can give an estimate of
the total amount of code lines all projects results in?

thanks in regads
Anders

Nov 19 '05 #4
> including one named 'Solution Statistics' which runs through all of
the files
and projects that are part of your solution and lists for you to
total number
of lines within, as well as how many of those lines are empty,
comments or
code.


To add to Brendan's reply, you could also copy the stats dialog
contents to the clipboard via Ctrl-C. I find it useful if I need to
share the results with somebody.
--
Sergey Mishkovskiy
http://www.usysware.com/dpack/ - DPack - free VS.NET add-ons
http://www.usysware.com/blog/

Nov 19 '05 #5
There is a Statistics feature in my add-in (below). It counts code lines,
comment lines, total lines, percentages, classes, functions and so on...

--
Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
You can code, design and document much faster.
Free resources for add-in developers:
http://www.mztools.com

"Anders K. Jacobsen [DK]" <no**@at.all> escribió en el mensaje
news:uO*************@TK2MSFTNGP15.phx.gbl...
Hi

We have a rather large asp.net project with serveral utility projects
(written in C#). Is there at tool out there which can give an estimate of
the total amount of code lines all projects results in?

thanks in regads
Anders

Nov 19 '05 #6

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

Similar topics

6
by: Dale Atkin | last post by:
As part of a larger project, I need to be able to count the number of lines in a file (so I know what to expect). Anyways, I came accross the following code that seems to do the trick, the only...
1
by: VM | last post by:
How can I know how many lines of code are in my solution (which consists of two projects)? Thanks.
5
by: Anders K. Jacobsen [DK] | last post by:
Hi We have a rather large asp.net project with serveral utility projects (written in C#). Is there at tool out there which can give an estimate of the total amount of code lines all projects...
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...
4
by: Peter | last post by:
Currently I'm using the method below, is there someting more efficient?: Imports System.IO Public Class CountLine Public Shared Function CountLines(ByVal FileName As String) As Integer Dim fs...
5
by: andy.lee23 | last post by:
hi im having trouble counting lines in a text file, i have the following code int node1, node2, i; char name; float value; ifstream fin; fin.open(OpenDialog1->FileName.c_str()); i=1;
10
by: cj | last post by:
I'm writing a TCP/IP server app that will have many simultaneous connections. The main thread listens for new connections and starts a thread to handle each requested connection. These are short...
14
by: Dan | last post by:
Is this discouraged?: for line in open(filename): <do something with line> That is, should I do this instead?: fileptr = open(filename) for line in fileptr: <do something with line>
7
by: peraklo | last post by:
Hello, there is another problem i am facing. i have a text file which is about 15000 lines big. i have to cut the last 27 lines from that file and create a new text file that contans those 27...
1
by: powerej | last post by:
I have gotten the part of counting how many words are in the string, but the vowels just seem alien to me. Ive tried so many things but never close to a correct answer. I know I need to use...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...

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.