LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

corrupted file

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

0 Kudos
Message 1 of 8
(3,033 Views)

Hi shamaran,

can you explain what you mean with corrupt? When is your file corrupt?

 

Mike

0 Kudos
Message 2 of 8
(3,026 Views)

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

0 Kudos
Message 3 of 8
(3,015 Views)

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

0 Kudos
Message 4 of 8
(3,013 Views)

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

0 Kudos
Message 5 of 8
(3,010 Views)

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

0 Kudos
Message 6 of 8
(3,006 Views)

thanks mike. 

 

i do welcome if there are any other suggestions.

 

thanks

 

regards

shamaran

0 Kudos
Message 7 of 8
(2,994 Views)

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...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 8 of 8
(2,986 Views)