How Do I Append to a Text or Binary File in LabVIEW?
Primary Software: LabVIEW Development Systems>>LabVIEW Professional Development System
Primary Software Version: 1.0
Primary Software Fixed Version: N/A
Secondary Software: N/A
I am using the Open/Create/Replace File VI to open a file. When I write to the file multiple times in the program the data stored in the file is being overwritten with new data on each write. How do I append data to the end of the file on each file write?
LabVIEW 8.0 or later:
Use the Set File Position VI found on the Functions palette under Programming»File I/O»Advanced File Functions. Set the from (0:start) enumerated input of this VI to “end”. Connect the refnum outfrom the Set File Position VI to the file input of the VI that is writing to the file. This will append new data to the end of the file. The image below shows an example of appending a string value to a text file. The End of Line Constant is concatenated to the string input in this case to create a new line for every value written to the file. This constant is not needed if an array type is entered into the Write to File VI because it will automatically append it to the value.
For more information about the Set File Position VI, see LabVIEW 8.6 Help: Set File Position.
The Write File function on the File I/O Palette has an input called pos mode (0:2). Right-click this input and select Create»Constant. This will create an enumerated constant. By selecting End, the new data that you are writing to the file will be appended to the end. Note that it may be necessary to do a line break / carriage return.
Note: For the Binary File VIs ( Write to I16 File VI or Write to SGL File VI), wire a True constant to theAppend to File input.
LabVIEW 8.6 Help: File I/O VIs and Functions
LabVIEW 8.6 Help: Set File Position
Developer Zone Example: Writing a Text File from an Array of Strings