473,403 Members | 2,338 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,403 software developers and data experts.

Get Line Count from a File

Hi All,

I'm hoping there's a quick and easy to accomplish this:
I've got a CSV file (each row represents a record, and is followed by a
NewLine).
Is there any way (short of counting the NewLine's) to get a Line Count of
the file.

I've got a quick & dirty utility that I wrote for a client, and right now,
they run the utility and it checks for the existence of the CSV file. If
it's found they get a messagebox like
"File exists, task needs to be run"
I would like in addition for checking for the file's existence, get the line
count and present a message like:
"File exists, task needs to be run, and there are XX records to process"

Thanks,
Brian
Oct 5 '07 #1
2 8514
On Oct 5, 4:06 pm, "Brian Simmons" <centr...@newsgroup.nospamwrote:
I'm hoping there's a quick and easy to accomplish this:
I've got a CSV file (each row represents a record, and is followed by a
NewLine).
Is there any way (short of counting the NewLine's) to get a Line Count of
the file.
Well, I wouldn't count the newlines by hand. I'd either call
TextReader.ReadAllLines and return the length of the array, or (if I
thought the file might be largish) keep a count and call ReadLine
until it returned null.

Jon

Oct 5 '07 #2
Perfect Jon, works like a charm. Thanks!

"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:11**********************@g4g2000hsf.googlegro ups.com...
On Oct 5, 4:06 pm, "Brian Simmons" <centr...@newsgroup.nospamwrote:
>I'm hoping there's a quick and easy to accomplish this:
I've got a CSV file (each row represents a record, and is followed by a
NewLine).
Is there any way (short of counting the NewLine's) to get a Line Count of
the file.

Well, I wouldn't count the newlines by hand. I'd either call
TextReader.ReadAllLines and return the length of the array, or (if I
thought the file might be largish) keep a count and call ReadLine
until it returned null.

Jon

Oct 5 '07 #3

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

Similar topics

4
by: Amit Kulkarni | last post by:
Hi, I have small problem. I want to truncate a line in a text file using C file handling functions and write new line in place of it. How do I do it? e.g. "example.txt" Line 1: This is a...
11
by: name | last post by:
Here is a first attempt at a line/word wrapping utility. Seems to work okay, but lacks some checking stuff, etc. --------------------------------------------------------- #include <stdio.h>...
9
by: Jonny | last post by:
Hi, Please could you tell me what the quickest way would be to verify that a line of text exists in a file. I would like to be able to do something like: grep "^line of text$" filename.txt...
4
by: News | last post by:
Hi Everyone, The attached code creates client connections to websphere queue managers and then processes an inquiry against them. The program functions when it gets options from the command...
9
by: Adi | last post by:
Hello eveyone, I wanna ask a very simple question here (as it was quite disturbing me for a long time.) My problem is to read a file line by line. I've tried following implementations but still...
1
by: gdarian216 | last post by:
okay I had a code that asked user to input a file name and instead i changed it to take the input from the command line. I now want to output results of some functions to an output file. I have...
15
by: Sullivan WxPyQtKinter | last post by:
I have a huge log file which contains 3,453,299,000 lines with different lengths. It is not possible to calculate the absolute position of the beginning of the one billionth line. Are there...
6
by: bmerlover | last post by:
I'm trying to read each line, character by character, to determine if a line has a semicolon in it. I'm trying to count the number of lines that have a semicolon. In all of the files in one...
16
by: lovecreatesbea... | last post by:
It takes mu so time to finish this C source code line count function. What do you think about it? / ******************************************************************************* * Function ...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
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.