Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Count how many lines in a text file

Status
Not open for further replies.

dinoviapangea

Technical User
Apr 9, 2002
41
US
How can a get the number of lines in a text file? The file may or may not be a queryable file, just any text file. Any suggestions would greatly be appreciated.

Thanks,
Dino
 
How is the file organized? Are there line breaks? If so, you can treat the whole file like a list and count the members:

<CFFILE ACTION="READ" file="whatever" variable="myfile">
<cfset myfilelist = myfile>
<cfset linecount = listlen(myfilelist,chr(13))>
<cfoutput>#linecount#</cfoutput>
Be cautioned that this method won't count blank lines, so you'd have to do something like replace consecutive chr(13)'s with chr(13)&blah&chr(13).

HTH,

Phil Hegedusich
Senior Programmer/Analyst
IIMAK
-----------
I'm not as think as you confused I am.
-----------
Flabbergasted (a.): Amazed at how much weight one has gained.
-----------
Oyster (n.): One who sprinkles their conversation with Yiddish expressions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top