473,808 Members | 2,855 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2459
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.Collecti ons.Generic;
using System.Text;
using System.IO;

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

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

public static void ShowProjectLine Count(Directory Info d)
{
// Curr dir.
FileInfo[] fis = d.GetFiles("*.c s");
foreach ( FileInfo fi in fis )
{
using ( StreamReader sr = fi.OpenText() )
{
string line;
int lineCount = 0;
while ( (line = sr.ReadLine()) != null )
{
lineCount++;
}
totalCount += lineCount;
Console.WriteLi ne("{0} {1}", lineCount, fi.FullName);
lineCount = 0;
}
}
// Subdirectories.
DirectoryInfo[] dis = d.GetDirectorie s();
foreach ( DirectoryInfo di in dis )
{
ShowProjectLine Count(di);
}
}
}
}

--
William Stacey [MVP]

"Bruce" <co*********@ne wsgroup.nospam> wrote in message
news:%2******** ********@TK2MSF TNGP09.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.o rg> wrote in message
news:uF******** ******@TK2MSFTN GP11.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.Collecti ons.Generic;
using System.Text;
using System.IO;

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

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

public static void ShowProjectLine Count(Directory Info d)
{
// Curr dir.
FileInfo[] fis = d.GetFiles("*.c s");
foreach ( FileInfo fi in fis )
{
using ( StreamReader sr = fi.OpenText() )
{
string line;
int lineCount = 0;
while ( (line = sr.ReadLine()) != null )
{
lineCount++;
}
totalCount += lineCount;
Console.WriteLi ne("{0} {1}", lineCount, fi.FullName);
lineCount = 0;
}
}
// Subdirectories.
DirectoryInfo[] dis = d.GetDirectorie s();
foreach ( DirectoryInfo di in dis )
{
ShowProjectLine Count(di);
}
}
}
}

--
William Stacey [MVP]

"Bruce" <co*********@ne wsgroup.nospam> wrote in message
news:%2******** ********@TK2MSF TNGP09.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
61422
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: in_file = raw_input("What is the name of the file you want to open: ") in_file = open("test.txt","r")
24
7309
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 > corpus.uniq corpus.uniq is 80G large. The fact that every sentence appears only
1
6934
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 with uploaded MS WORD .doc files. Using code like that below: strLine = sr.ReadLine While Not IsNothing(strLine) 'Not eof If Trim(strLine) <> "" Then 'Not blank
6
1979
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
24159
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 like to split it and create a new file at every lets say 20000 lines... so, the directory output would have to be something like this:
19
3807
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 tool cccc , but iam getting many parse errors with it. If you know any other tool( to be used in linux) please let me know.
3
3598
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. ------------------------------------------------------------------------------ #!/usr/bin/python import fileinput # cycle through files for line in fileinput.input(): if (fileinput.isfirstline()): if (fileinput.lineno 1):
4
2227
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 scenario: i take a input from a file, i count the length ofcertian paramater with substring and do the if else condition. but i have to perform this action in every line.... a code snippet...
9
13240
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 numOfLines = 0; byte bArr = new byte;
1
1439
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 new record in the traffic table with that value based on a unique PCID. This code is triggered by the click event of a button on my form after someone enters a new traffic count into my continuous form. The code takes the old count and puts it into...
0
9721
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9600
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10628
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10373
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10113
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7651
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6880
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5547
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
3011
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.