[net.micro.pc] DOS FUNCTION CALL hex 21 - File Size

ijk@houxt.UUCP (05/31/84)

I'm writing a test routine to use this function call to determine
a file's size.  Despite all my efforts, this routine seems to
insist that my file is only one record long.  Has anyone out there
used this func call?? If so, was there anything special that you
had to do??
Thankx in advance
Ihor Kinal
houxt!ijk

broehl@wateng.UUCP (Bernie Roehl) (06/01/84)

I assume the original poster meant function 23, not 21; the correct
procedure is to load AH with 23 hex, load the DS:DX registers with
a pointer to a formatted but unopened FCB, and then do an INT 21h.
This will return return a null byte in AL if the operation was okay,
or an FF hex if not.  If the operation was successful, the random record
field of the FCB will contain the file size in records.
Note that this will be 1 if your file is smaller than the record size
field of the FCB prior to the call!  This may well explain your problem.

Note that under Dos 2.00 and above, there are better ways of finding
a file's size; for example, the Find First Matching function (hex 4E)
returns a block of information about a file, including the file's date
and time, the size in bytes, and the file's attribute byte.
The other advantage of the hex 4E call is that it doesn't require you
to set up an FCB; just point DS:DX at an ascii string giving the path/file
string for the file (optionally including drive specifier), terminated by
a null byte.  (Sound like a C string?  You bet!).

Under various C compilers, you can also use lseek to find the file size;
just lseek to the end of the file, and the (long) value returned by lseek
is the size of the file in bytes.


-- 
        -Bernie Roehl    (University of Waterloo)