Question : How would I determinine the difference (programmatically) between a word and wordperfect document in a foxpro General field?

I work for a company that needs a automated solution to extract the general and memo fields from a large database. the general field houses WordPerfect and Microsoft word files. I need to figure out how to determine what they are at runtime. We were going to use dates, but different offices switched from WPD to DOC files at different times(we dont know when).
I can extract the word files just fine, have not written code to extract the WPD files yet though. what I need to know is if anyone knows a way to determine what kind of file is in the Gen field at program execution time (runtime). if you have code ideas, please submit, if you have any ideas, please submit!

questions? please ask.

Thanks and have a fantastic holiday!
-Jason
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
* MS Word Extraction *
USE inspctn.dbf
GO top

SCAN
IF (ISBLANK(inspctn.ciulkey) = .F.)
loForm = CREATEOBJECT("Form")

* - create the word object - 
oWord = CREATEOBJECT("Word.Application") 
 
loForm.addobject("oleboundcontrol1", "oleboundcontrol") 
loForm.oleboundcontrol1.autosize = .T. 
* bind general field to oleboundcontrol 
loForm.oleboundcontrol1.controlsource = "inspctn.gnarrative" 
* save data from general field to .doc file 
loForm.oleboundcontrol1.saveas("c:\TestFolder\"+ inspctn.ciulkey + "_2.doc") 

* open the word file to be merged 
oWord.Documents.Open("c:\TestFolder\"+ inspctn.ciulkey + "_2.doc") 

oWord.ActiveDocument.PageSetup.PageWidth = "8.5"
oWord.ActiveDocument.PageSetup.PageHeight = "11"

oWord.Activedocument.saveas("c:\TestFolder\"+ inspctn.ciulkey + "_2.doc")
oWord.Activedocument.close
oWord.Application.quit

RELEASE oWord
RELEASE loForm

Answer : How would I determinine the difference (programmatically) between a word and wordperfect document in a foxpro General field?

First few bytes of each file represents its format obviously.
Word .DOC has: D0 CF 11
WordPerfect: FF 57 50 43

This should be sufficient enough to recognize these two file types (see code snippet).

But you probably need to know the file type prior to its extraction... One trick exists - create a copy of your table (or a copy of just one record) and change the General field data type to Memo by direct change in DBF heading (you have to use low level file function or hexeditor). Then you may read the memo and look for above byte sequences and other values.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
lnH = FOPEN("c:\TestFolder\"+ inspctn.ciulkey + "_2.doc")
IF lnH < 0
  *-- Error opening file
ENDIF

lcHdr = FREAD(lnH, 3)  && You may read more bytes...
=FCLOSE(lnH)

DO CASE
CASE ASC(lcHdr) = 0xD0 AND ASC(SUBSTR(lcHdr, 2, 1)) = 0xCF AND ASC(SUBSTR(lcHdr, 3, 1)) = 0x11
  *-- Word .DOC file

CASE ASC(lcHdr) = 0xFF AND ASC(SUBSTR(lcHdr, 2, 1)) = 0x57 AND ASC(SUBSTR(lcHdr, 3, 1)) = 0x50 AND ASC(SUBSTR(lcHdr, 2, 1)) = 0x43
  *-- WordPerfect file

OTHERWISE
  *-- Unknown file
ENDCASE
Random Solutions  
 
programming4us programming4us