Results 1 to 1 of 1
2001-03-24, 03:04 #1
- Join Date
- Feb 2001
- Yilgarn region of Toronto, Ontario
- Thanked 0 Times in 0 Posts
Code: Function boolWP51Doc(strFile As String) As B
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:
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"
MsgBox "not a wp product"
MsgBox "not a WPC header"
'MsgBox boolWP51Doc("i:greavestrainingwordpr~1wp51Maths.w5 1") ' true
'MsgBox boolWP51Doc("i:greavestrainingwordpr~1wp51Alto.wpm ") ' false