LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I read the number of lines of one file?

I have an application that uses a file created before by the user, and this information will be used in a automatic program that executes a lot of steps. The information about these steps are recordered in this file. And I need to know how many lines this file has.

Any help will be appreciated.
0 Kudos
Message 1 of 3
(2,672 Views)
I'm assuming you mean an ascii text file. Go into the read from spreadsheet file VI (in the file palette) by double clicking it and use the instructions on its diagram to modify it to read string arrays. Save this VI under a different name. Wire your file into this new read function and you should get a 2D array out. Use the array size VI to find the number of rows in the array.

___________________
Try to take over the world!
0 Kudos
Message 2 of 3
(2,664 Views)
The attached vi will open a file, get the EOF location, then read lines from a file until EOF is reached. The iteration counter, i, will contain one less than the number of lines that was read, because i starts with 0. Just add 1 to i after the loop and viola, you have the number of lines in a file. Beware, if the file does not contain any end of line constants, there will be an error. You could easily trap that error and report the number of lines as zero. Or if you get the error and the string length from the read function is greater than zero, you might want to count that as one line.
- tbob

Inventor of the WORM Global
0 Kudos
Message 3 of 3
(2,654 Views)