I want to append text to a existing text file at the start of the file without that the data the file already contains gets overwritten... Does LabVIEW have a VI for this? The VI's in the FILE I/O pallet don't cut it... in the example below my existing data just gets overwritten...
File contains "12346789" after appending "test56789"
No. The way files are stored on disc is sequential. To prepend data to the front you must move every byte in the file to make room for it. The only way that works in practice is to read the entire file, place the new data where you want it, and then write all the data to the file.
One approach which might work for you is to append the new data to the end of the file while you are gathering the data. When you are finished, read it in, reverse the order of the rows/lines and write it back to the file in the desired final order.
Unfortunately, what you have is an operating system limitation, not a LabVIEW limitation. You'd have the same exact problem in any other programming language. You didn't indicate what is "inefficient" about this. If you are dealing with a very large file and you are concerned about memory then another option is to first write out the prepended data (note the use of the word prepend rather than append, which is to add to the end) to a temporary file, then read in the original file in chunks and append them to this temporary file. Your temporary file will be the original with the prepended data. Here you are substituting file I/O for memory.
You can also do this in-place in a single file, but will need to buffer the "replaced" data. The sequence would be something like this:
The 65,000 byte value is the optimum for fast file transfer under Windows (all flavors, all disk format types), but I have not tested it under linux or OSX. If you need more details, let us know.
I am trying to prepend a string to the beginning of a text file but cannot get the "concatenate" or "build array" VI's to append my old data to the end of my new data. Initially, I am writing text to a file in a while loop for some duration of time. After I stop the while loop, I would like to prepend a string prior to the data recorded in the while loop when I open the data file but I cannot successfully append this "old" data to the end of my string.
What am I missing conceptually? I would prefer to write the data immediately rather than wait. All I want is to have a string control to allow me to take notes as the program is running then be able to have these notes show at the beginning of my data.
I'd appreciate any help or direction as I am completely stumped; thanks,