From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Modify a string file without replace it

I need to replace only one line of a string file without replace the entire file. The file is very important and i dont want to lose it if the pc shutdown while the entire file is written. 
0 Kudos
Message 1 of 4
(2,340 Views)
If the lines are fixed length, you may use the binary vi's to write only the portion to be updated. You need to know the exact offset of the line to be changed, though.
This option, anyway, only minimizes the possibility to damage the file. When you modify a file, there is always a possibility to loose data (in fact the probability is usually very small).
If you really want to be sure, you may for example maintain two twin files, to be written in sequence; if something goes wrong with one of them, the other will still be ok, with the only possible exception of the last update.
No hope if your HD fries, however...

Paolo

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
Message 2 of 4
(2,335 Views)

If the data in the file is that important, perhaps it shouldn't be stored in a file but in something like a database?

Mike...

 


Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 3 of 4
(2,323 Views)
Read in the old file, modify it in memory and then write to a new file.

When all this is done, delete the old file and then copy the new file (new name) to where the old file was (old name) - you now have two new files.  Then delete the new file with the new name.  Bingo.

This way you should always have at least one version of the file intact.

Of course what you can't really control is the cacheing performed by the OS when writing to the disk.  In this case, it's maybe best to rename the old file to a standard name instead of deleting it.  Of course if this standard file already exists, it will have to be deleted first......

Old file > memory
Memory > changed memory
Changed memory > new file
old file > renamed old file
new file > copy of new file (same name as the original old file)
new file > deleted

Shane.

Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
0 Kudos
Message 4 of 4
(2,303 Views)