Reading text files and checking for corruption
Morning all !
I'm writing a program that reads x amount of text files.
Each file has a header record, a bunch of detail records and then a footer record.
Due to the nature of these files it is possible that some can be corrupted.
Problem is they could be corrupted anywhere within the file.
Now ... I can code this with loads of IF THEN statements as I pluck each field out from each row, but I know there must be a neater way of checking them record by record, probably using a routine of some kind.
Has anyone out there done anything similar ? I'm just looking for a "neat" a way as possible really, rather than my old archaic way of doing things.
Thanks ....
Re: Reading text files and checking for corruption
What do you mean by corrupt? Not the right length, not the correct number of records as per header / footer, incorrect total as per header / footer?
Re: Reading text files and checking for corruption
No the record data can contain "rogue characters" or spaces where it shouldn't.
Basically the format gets right of step.
Normally happens in the middle of the file, but has the potential to happen anywhere.
Re: Reading text files and checking for corruption
You'd have to parse each field or each record (depending on the actual file format). You could do it in a loop to save code, but there's no TextIsCorrupt() function or anything like that. Depending on what "rogue character" means, and whether spaces are allowed in some places but not others, or just not allowed, the code could be simple or it could be complex. (Whichever, it's going to be slow if you implement it in VB.)
Re: Reading text files and checking for corruption
Yeah thats what I was afraid of !
Re: Reading text files and checking for corruption
if it gives an error when your program gets to a corruption in the data, you can just put error handling to do whatever is required to fix when an error happens