Here is a procedure which tests to see if a file is a Wordperfect 5.1 (DOS) document file.

I have a table of file characteristics for different files, such as GIF files, PKZip files, Excel spreadsheet files, AmiPro documents and WordPerfect documents. For example:

Bytes Contents
===== ========
0 X"FF"
1-3 "WPC"
4-7 data offset
8 product X'01' is WP
9 document type X'0A' is document, X'01' is macro
10 version 0 is WP51, 2 is WP6
11 minor version e.g. X'01' for version 1?

The simplified example is not exhaustive. It does not check file length, which it should. It checks only bytes 1-3 and 8 and 9. It does not check byte 0 for X'FF'; it does not check that the data offset is valid, and so on.

Nonetheless, if I just happened to want to count all the WPerfect files on a system, it would give me a pretty good estimate. heh heh!.

I could embed my various tables in code and have a really neat type-of-file identification function.

<pre>Public Function boolWP51Doc(strFile As String) As Boolean
' Procedure : boolWP51Doc
' Description: Test if a file is a WordPerfect 5.1 (DOS) document file.
' Copyright: Chris Greaves Inc.
' Inputs: File name..
' Returns: TRUE if test is successful.
' Assumes: File exists, is of required minium length.
' Side Effects: None.
' Tested: By the calls shown below.

boolWP51Doc = False ' default is failure
Dim intFile As Integer
intFile = FreeFile
Open strFile For Binary As intFile
If boolChar(intFile, "WPC", 1) Then
If boolHex(intFile, "01", 8) Then
If boolHex(intFile, "0A", 9) Then
boolWP51Doc = True ' matches on 3 known criteria
MsgBox "not a doc"
End If
MsgBox "not a wp product"
End If
MsgBox "not a WPC header"
End If
Close intFile
'Sub TESTboolWP51Doc()
'MsgBox boolWP51Doc("i:greavestrainingwordpr~1wp51Maths.w5 1") ' true
'MsgBox boolWP51Doc("i:greavestrainingwordpr~1wp51Alto.wpm ") ' false
'End Sub
End Function