Need to get count of lines in the large text file

Reading file line by line, but need the total lines count to display a progress…

Any suggestions? need something faster than ReadLineEx

Yea, that’s true. Instead of showing progress as number of lines, you can show it as position in file. If it’s a percent value then no on will know the difference.

scan for CR and/or LF depending on what your line style is? Not sure it’ll be quicker but you may be able to optimise it for media sector size?

Unless the deleted post was “all I really need is the % thru the file” then I’m not sure Andre’s option will give you the line count

Deleted post was a duplicate of the original.

Speed is not that important, but some larger files are pretty large, and to get line count could take several minutes.

Displaying progress using position in the stream is acceptable solution.
Thanks!

1 Like

Did that, not much faster. I mean it is fast but could still take minute or more to count lines in 100 mb file and this is just too long.

@ EvoMotors - Why not store the number of lines as the last line of the file? I’m assuming its G-Code, so hide it in a comment.