Int 21H [1.0] Function 23H (35) Get file size

Searches for a matching file in the current directory; if one is found, updates the FCB with the file's size in terms of number of records.

Call with:

AH = 23H

DS:DX = segment:offset of unopened file control block

Returns:

If function successful (matching file found)

AL = 00H

and FCB relative-record field (offset 21H) set to the number of records in the file, rounded up if necessary to the next complete record

If function unsuccessful (no matching file found)

AL = FFH

Notes:

An appropriate value must be placed in the FCB record-size field (offset 0EH) before calling this function. There is no default record size for this function. Compare with the FCB-related open and create functions (Int 21H Functions 0FH and 16H), which initialize the FCB for a default record size of 128 bytes.

The record-size field can be set to 1 to find the size of the file in bytes.

Because record numbers are zero based, this function can be used to position the FCB's file pointer to the end of file.

Example:

Determine the size in bytes of the file MYFILE.DAT and leave the result in registers DX:AX.

myfcb db 0 ; drive = default

db 'MYFILE ' ; filename, 8 chars

db 'DAT' ; extension, 3 chars

db 25 dup (0) ; remainder of FCB

.

.

.

mov ah,23h ; function number

mov dx,seg myfcb ; address of FCB

mov ds,dx

mov dx,offset myfcb

; record size = 1 byte

mov word ptr myfcb+0eh,1

int 21h ; transfer to MS-DOS

or al,al ; check status

jnz error ; jump if no file

; get file size in bytes

mov ax,word ptr myfcb+21h

mov dx,word ptr myfcb+23h

.

.

.