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 function to open a file. When I write to the file multiple times, 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 function 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 out from the Set File Position function 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 Text File function because it will automatically append it to the value.
For more information about the Set File Position function, see LabVIEW 2009 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 the Append to File input.
LabVIEW 2009 Help: File I/O VIs and Functions
LabVIEW 2009 Help: Set File Position
Example Programs: Write Array of Data to Text File with Headers
Append To File.vi
Report Date: 09/25/2006
Last Updated: 03/31/2017
Document ID: 41OICUQ0