BBS: Inland Empire Archive Date: 12-27-92 (12:27) Number: 384 From: DIK COATES Refer#: NONE To: CHRIS HOLTEN Recvd: NO Subj: Re: fcb's Conf: (2) Quik_Bas
>>>> QUOTING Chris Holten to Francois Roy <<<<
CH> In a message of <18 Dec 92 13:56:32>, Francois Roy (1:163/506.2)
>FR : SP> This is probably a dumb question, but here it goes. I need to
>FR :get the
>FR : SP> size of a file.
CH> Gotta do something more exotic so's yer basic code will
CH> look more like some highly structured language with some
CH> Ax's, Dx's, Ah's and such whatnot's in it <chuckle>. Gotta
CH> keep that spaghettie level down you see.
Was feeling kinda silly, so came up with the following... and added it
to my library... Feel free to use it in your programs...
; Copyright (C) 1992 by R.A. Coates, All Rights Reserved
;
; DECLARE FUNCTION FLENGTH& (filename$, errval%)
.Model Medium, Basic
Extrn StringAddress:Proc ;part of PDS
.Code
oldint dw ?
buff80 db 80 dup(?) ;80 byte buffer to hold string values
; BASIC LANGUAGE FILE LIBRARY FUNCTION - FLENGTH&()
;
; Returns the length of a file as a Long Integer, if the function
; is successful, otherwise, it returns a zero value. The DOS
; Critical Error Value is returned as errval%, if the Function
; fails. The procedure works by opening a file, setting an offset
; from the end of the file, and reading back the new file pointer
; location. The file is then closed.
;
;
; The function declaration is as follows:
;
; DECLARE FUNCTION FLENGTH& (filename$, errval%)
;
;
; The Arguments are:
;
; filename$ - name of file to determine length of
;
; errval% - DOS Critical Error Value
;
;
; LIB: BAFIL.LIB
;
;
; REV: 92-12-26
FLENGTH proc uses bx cx ds es si di, dsrptr:word, errval:word
mov ax, 3524h ;DOS get int 24h vector
int 21h
mov ax, es:[bx]
mov cs:oldint, ax ;save old vector to oldint
mov word ptr es:[bx], 00CFh ;replace it with IRET call
mov ax, dsrptr
push ax ;load ax on stack for call to StringAddress
call StringAddress
mov ds, dx ;set up the source in ds:si
mov si, ax
push cs
pop es ;set up the destination in es:di
lea ax, buff80
mov di, ax
shr cx, 1 ;divide by 2 to move words
rep movsw ;until cx is 0
jnc FLen1 ;if odd num of bytes in
string, carry flag set
movsb ;move last byte if odd number
FLen1: mov es:[di], cl ;add terminating NUL es:ax points to buff80
mov dx, ax
push es
pop ds ;ds:dx pointer to buff80
mov ax, 3D00h ;DOS open file
int 21h
jc FLenError ;if cf clear, handle in ax
mov bx, ax ;put handle in bx
mov ax, 4202h
xor dx, dx ;dx(lsb), cx(msb) offset set to 0
int 21h ;Function 42h, ax = 02-from eof
jc FLenError ;if cf clear, dx(msb),
ax(lsb) length of file
mov cx, ax ;save ax in cx
mov ax, 3E00h ;handle still in bx
int 21h ;Function 3Eh, close file
jc FLenError
jmp FLenExit ;exit with file length in dx, ax
FLenError: mov bx, errval ;carry flag not clear, ret crit err
mov ss:[bx], ax ;ss and DGROUP are one and the same
xor cx, cx ;make cx=0 and swap with ax on exit
xor dx, dx ;return 0 as Function value
FLenExit: mov ax, 3524h ;DOS get int 24h vector
int 21h
mov ax, cs:oldint
mov es:[bx], ax ;restore old value
mov ax, cx ;restore ax
ret
FLENGTH Endp
end
It even handles accessing a file on drive a: when the gate's left
open... had to write an interrupt handler to cover that... goes
great with pasta...
Regards Dik, Oshawa, Canada
... Bad command or filename. Go stand in the corner.
___ Blue Wave/QWK v2.10
--- Maximus 2.00
* Origin: Durham Systems (ONLINE!) (1:229/110)

Books at Amazon:
Back to BASIC: The History, Corruption, and Future of the Language
Hackers: Heroes of the Computer Revolution (including Tiny BASIC)
Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution
The Advent of the Algorithm: The Idea that Rules the World
Moths in the Machine: The Power and Perils of Programming
Mastering Visual Basic .NET