
June 15th, 2005, 08:49 AM
|
|
Contributing User
|
|
Join Date: Sep 2004
Posts: 108
Time spent in forums: 11 h 16 m 54 sec
Reputation Power: 5
|
|
Quote: | Originally Posted by bandoola Is there a way for vb to check if a file is corrupt?
The problem i m facing is that some files i downloaded by my ftp program is corrupt. I would like to add some codes to check whether the downloaded files are corrupt.
Thanks in advance |
Some years ago (20 years...) my brother give me some disks without files and said that there where some huge files (huge in it's time) with a database and wanted it to be recovered. I tried a norton unerase utility but without success, so I make a file with all the disk area and a program to filter out garbage.
The trick is you can compare the data with a pattern that you have (symbols, dates, even that a date is greater than other in the row). This aproach work fine with ascii files and the file I am talking about was done with btree (and ratter old DB and mostly ASCII).
There are other aproaches, but the easyest could be to obtain a checksum byte that represent all the file, you can add each ascii value (65=A...) to a single value that represent all the characters on the file and if the checksum value is OK the file is OK. Some guys do it in a byte or two byte value so if the value is bigger than the maximum, no problema just obtain the range taking off the max value.
Code:
Private Sub Command1_Click()
Dim j As Byte, k As Long, i As Byte
TXT = "Hi there, it has been a pleasure to talk about"
j = 0
For i = 1 To Len(TXT)
k = Asc(Mid(TXT, i, 1))
If j + k > 255 Then j = j + k - 255 Else j = j + k
Next i
MsgBox j
End Sub
"Hi there, it has been a pleasure to talk about" = 68
The procedure can be applied even with each character readed from a file in a binary (non ascii) file.

|