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.