LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Delete line from file

Hi, I have a VI that needs to store a lot of data into a file. When the file will be with a number of lines determined before, it will need to delete the second line and, so, make one more recording. And, everytime I want make more recordings, it will do this: delete the second line and, so, make one more recording. There's a way to delete this second line from file? I'll save to a txt file.
0 Kudos
Message 1 of 3
(3,170 Views)
There's no way to delete a line from a file without reading and rewriting the whole file.
You don't have to read it all at once - you can do it a line at a time, but you do have to go through it all.
Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 2 of 3
(3,155 Views)
There are some questions left:

You have a multi line file and you will keep the first line of the file and delete all lines from the second line?

You have a multi line file and want to overwrite the lines beginning with the second line?

For the first case the solution is simple. Open the file read in the first line. After that use the EOF function from the Advanced File Functions palette to set End of File at the current position. This truncates the file and any new write will start after the first line.

The second case is more complicated. If the lines have all the same length you can open the file, read the first line and start writing the next lines. If the lines are different in length you need a second file. Open the files. Read the first line from the first file and write it to the second file. For each line written to the second file read a line from the first file. At the end copy the remaining lines from the first file to the second file. Be sure to handle EOF from the first file if it will contain not as much lines as you are writing into the second file.
Waldemar

Using 7.1.1, 8.5.1, 8.6.1, 2009 on XP and RT
Don't forget to give Kudos to good answers and/or questions
0 Kudos
Message 3 of 3
(3,151 Views)