01-01-2012 04:32 PM
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"
01-01-2012 07:50 PM
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.
01-02-2012 09:17 AM
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.
01-03-2012 09:26 AM
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.