Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HOW DISPLAY HEADER FILE INFORMATION? 3

Status
Not open for further replies.

OXIGEN

Programmer
Mar 12, 2002
11
0
0
PY
How I can see the information of the header file?. I know, the function header() return the number of bytes, but I need to display the content of the file header.

Somebody can help me?.
Thanks.
 
Try:

DISPLAY STRUCTURE
-or-
LIST STRUCTURE
Dave S.
 
You can use a modi comm on the dbf and the cdx. Of Course, caution is required when in the physical file.
 
Finally, if you need additional information from the .dBF file header, you can use low-level IO to read it all. The Help file provides a reasonable breakout of the structure, but if you need more, post back.

Rick
 
I make a routine for show the content of file header using low level function,
but I see stranger caracter and can not understand the information. Someone Can tell me why?
 
Assuming you are only concerned with non-VFP tables, this is the layout of the base header.
Code:
**  1            Type
**                 x03  FoxBASE+/dBASE III PLUS, no memo
**                 x83  FoxBASE+/dBASE III PLUS, w/ memo
**                 x03  FoxPro/dBASE IV, no memo
**                 xF5  FoxPro, w/ memo
**                 x30  Visual FoxPro (header is different)
**                 x8B  dBASE IV, w/ memo
**
**  2 -  4     * Last Update
**  5 -  8     * Number of records
**  9 - 10     * Position of 1st Record - Header Length-1
** 11 - 12     * Record Length
**
** 29            Structural Index File
**                 x00  None
**                 x01  Has ( FP -> .CDX, dB -> .MNX )
**
**             * -> in INTEL reverse byte order
**
When you get this part straight, then the variable header part has the field definitions from 30 to where 9-10 points.

Rick
 
Run this program to get the information you want...

close all

dimension dbfhdr[29]

private rdfile,ctype,nrecords,nposrec1,nreclen,lhascdx,nfldpos,cfield,cfldtype,nflddec,nfldlen,nfldcnt

cfldtype=''
nfldlen=0
nfldcnt=0


rdfile=space(30)

clear
@ 5,5 say 'Enter dbfname to investigate: ' get rdfile pict '@!'
read
rdfile=alltrim(rdfile)

if len(rdfile)=0
return
endif

file_handle=FOPEN(rdfile) && Open the file

if file_handle < 0
wait(rdfile+' NOT FOUND')
return
endif

=FSEEK(file_handle, 0,0) && Move pointer to first byte
bytecount=1
do while bytecount<30
dbfhdr[bytecount] = asc(fgets(file_handle,1))
* if you want to see the contents of these bytes
* remove the *
*if dbfhdr[bytecount]>0
* ? bytecount,dbfhdr[bytecount]
*endif
bytecount=bytecount+1
enddo

do case
case dbfhdr[1]=3
ctype='Foxbase/Foxpro/dBaseIII/IV no memo'
case dbfhdr[1]=131
ctype='Foxbase/dBaseIII with memo'
case dbfhdr[1]=245
ctype='Foxpro with memo'
case dbfhdr[1]=48
ctype='Visual Foxpro'
case dbfhdr[1]=133
ctype='dBaseIV with memo'
otherwise
ctype='Unknown type'
endcase
*calculate the number of records
nrecords=dbfhdr[5]+dbfhdr[6]*256+dbfhdr[7]*256^2+dbfhdr[8]*256^3
*calculete the record length
nreclen=dbfhdr[11]+dbfhdr[12]*256
*calculate the position of the first record
nposrec1=dbfhdr[9]+dbfhdr[10]*256
*determine if this dbf has a structural index file
lhascdx=iif(dbfhdr[29]=0,.F.,.T.)

? 'Headerinfo on '+rdfile
?
? 'Type :',ctype
? 'Last update :',tran(dbfhdr[2],'@L 99')+tran(dbfhdr[3],'@L 99')+tran(dbfhdr[4],'@L 99')
? 'Number of records:',ltrim(str(nrecords))
? 'Position 1st rec :',ltrim(str(nposrec1,5))
? 'Record length :',ltrim(str(nreclen,5))
? 'Struct Index File:',iif(lhascdx,'Yes','No')

* read field definitions...
* the field definitions start at byte 33
* so first move to that position

if dbfhdr[1]=3 or dbfhdr[1]=48 or dbfhdr[1]=131 or dbfhdr[1]=133 or dbfhdr[1]=245
=fseek(file_handle,32,0) && current position
? 'Structure of this dbf:'

do while fseek(file_handle,0,1) < nposrec1-32
nfldcnt=nfldcnt+1
cfield=fread(file_handle,11)
cfldtype=fread(file_handle,1)
nfldpos=asc(fread(file_handle,1))
=fseek(file_handle,3,1)
nfldlen=asc(fread(file_handle,1))
* if the field is type N find out how many decimals there are
if cfldtype='N'
nflddec=asc(fread(file_handle,1))
=fseek(file_handle,14,1)
else
=fseek(file_handle,15,1)
endif
? tran(nfldcnt,'@L 999'),cfield,'type', cfldtype,'Length',str(nfldlen,5)+iif(cfldtype='N','.'+ltrim(str(nflddec)),' '),'Startposition in record',str(nfldpos,5)
enddo

endif
=fclose(file_handle)
release all
return


Rob.
 
One small correction:

the dbfhdr[1] = 133 should be dbfhdr[1]=139

I've posted a more complete program as FAQ.
 
My pleasure Oxigen!

Have another look at the FAQ section, the file has been extended to read the visual foxpro files also.

Rob.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top