Assembly Language Help (alang.hlp) (Table of Contents; Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
GetFileSize
 Map                                       Up Contents Index Back
────────────────────────────────────────────────────────────────────────────
 
;* GetFileSize - Gets the size of an open file, specified by handle.
;*
;* Shows:   DOS Function - 42h (Set File Pointer)
;*
;* Params:  Handle - File handle
;*
;* Return:  Long integer with file size in bytes
 
GetFileSize PROC,
        Handle:WORD
 
        mov     bx, Handle              ; BX = file handle
        mov     ax, 4202h               ; AH = function #,
                                        ; AL = move to end of
        sub     cx, cx                  ;      file plus offset
        sub     dx, dx                  ; CX:DX = offset (zero)
        int     21h                     ; Set File Pointer
        mov     ax, dx                  ; Set DX:AX = file size in
        mov     dx, cx                  ;   bytes, return long int
        ret
 
GetFileSize ENDP
                                    -♦-