06-22-2010 02:47 AM
hai,
I would likee to know if its is possible to check a *.txt file if it is corrupted or not.
Im reading and file in 10 second interval and a CVI programme is writing to the same file every 10 second.
Do i need to check each loop whether the file is corrupted or not before i read the content of the file. If i need to check how to check the file?
thanks
regardsshamaran
06-22-2010 03:04 AM
Hi shamaran,
can you explain what you mean with corrupt? When is your file corrupt?
Mike
06-22-2010 04:16 AM
hai,
what i try to check is that once we read and write to the same file in the interval of 10 second for 24 7 is there any chances that the txt file get corrupted (corrupted in term of the file cannot be opened or read after some time). For example when we write to xml files there will be some time that we cannot open the xml file. when we open manually we can see the footer of the xml file is missing.
Is it necessary for me to check this condition when i write my programme.
thanks
regards
shamaran
06-22-2010 04:20 AM
Hi shamaran,
if you write from different programs to the same file, then you should lock the file for the writing process. You should make sure, that only one program writes at the same time, otherwise you will get race conditions.
Mike
06-22-2010 04:32 AM
hai Mike,
Thanks for your advice.Im locking the file for writing processes. As im doing the error checking for the code i developed ,is there a way to make sure the file is ok before i continue my with the next step of my code.This parameters in the files are critical and real time data. Analog signals will be send out depending on the value in this file.If i can conform the value in the file are ok then i will send the signal out .if i found any problem(corrupted) i wont send the signal out. How to counter check whether the file is readable???
hope my explanation is clear. thanks for ur kind replies
regards
shamaran
06-22-2010 04:37 AM - edited 06-22-2010 04:40 AM
Hi shamaran,
if you try to write critical data, why don't you use two or more different files? You can write a timestamp from each program and merge the files later.
Edit:
I don't think the file becomes corrupt if you close it correctly.
Mike
06-22-2010 05:04 AM
thanks mike.
i do welcome if there are any other suggestions.
thanks
regards
shamaran
06-22-2010 05:28 AM
Hi shamaran,
as a txt-file doesn't have a specified data structure (it's just a byte stream) you cannot detect data corruption easily.
As long as you close references properly (and the OS/filesystem plays nicely, and memory permits, and...) you will always be able to open a text file - it's just a byte stream. And it seems from your description you already handle errors due to simultanous file access...