Notifications
Clear all

[Closed] Counting the number of lines

Hi Guys,

I am having a bit of a problem trying to determine how many lines are in a text file (textInstructionFile – already defined).

I am trying to use this code but if errors after it prints ‘2’ when it gets to the second line.

textInFile = openFile textInstructionFile
s=stringstream (readLine textInFile)
totalNumberOfFrames = 1

while not eof s do
(
totalNumberOfFrames = totalNumberOfFrames + 1
print totalNumberOfFrames
skipToNextLine s
)

Can anyone see where I am going wrong?

Thanks for any help.

Spencer

2 Replies

Its ok I have just realised where I have gone wrong on that.

Here’s a shorter and probably faster method using .NET:

((dotNetClass "System.IO.File").ReadAllLines textInstructionFile).count

Cheers,
Martijn