I've got some corrupted files, RTF (rich text format) ones that were saved as .doc. In my Vb project I need to make sure that a .doc file really is a .doc one and not an RTF one with the wrong extension. How can I do that?
Thanks
Kati
Printable View
I've got some corrupted files, RTF (rich text format) ones that were saved as .doc. In my Vb project I need to make sure that a .doc file really is a .doc one and not an RTF one with the wrong extension. How can I do that?
Thanks
Kati
Well you could check the files extension but this would prove nothing. The only other way you could find out it drop them into notepad .rtf documents are mostly text and start with something like
{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fcharset0 Arial;}}
That may be time consuming depending on the number of documents but you could also write some code that checks the first couple bytes of the file. I know .doc documents start with a header like ÐÏ à¡ but I maybe wrong you really need to look up on the format it’s self
Can you please give me an example of how to open a .doc and check first bytes in vb?
hi try this. but bare in mind this is not the correct way. you really need to read on the format but if you only want it for basic stuff I shoud be ok.
VB Code:
Private Sub Command1_Click() Dim iFile As Long Dim sHead As String sHead = Space(4) iFile = FreeFile Open "C:\test.doc" For Binary As #iFile Get #iFile, , sHead Close #iFile If Not sHead = "ÐÏà" Then MsgBox "Is Not Word Document" Else MsgBox "Is Word Document File" End If sHead = "" End Sub
thanks a lot!! :wave: