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.
FindFirst
◄Example► ◄Back► ◄Contents► ◄Index►
──────────────────────────────────────────────────────────────────────────────
;* FindFirst - Finds first entry in given directory matching specification.
;*
;* Shows: DOS Function - 4Eh (Find First File)
;* Keywords - USES
;* Instructions - ret pushf popf
;*
;* Params: attr - Attribute code (see header comments for CreateFile)
;* fspec - Pointer to ASCIIZ file specification
;* finfo - Pointer to 43-byte buffer to receive
;* data from matched entry
;*
;* Return: Short integer with error code
;* 0 if successful
;* 1 if no match found
.DATA
old_dta DD WORD PTR ? ; Storage for old DTA address
.CODE
FindFirst PROC \
USES ds, \
attr:WORD, fspec:PTR BYTE, finfo:PTR BYTE
push ds ; Pass far pointer
mov ax, OFFSET @data:old_dta; to old_dta
push ax
call GetDTA ; Get current DTA address
add sp, 4 ; Adjust stack
mov cx, attr ; Load CX with file attribute
LoadPtr ds, dx, finfo ; DS:DX points to 43-byte buffer
push ds ; Make this new DTA
push dx
call SetDTA ; Set 43-byte buffer as DTA
add sp, 4 ; Adjust stack
LoadPtr ds, dx, fspec ; Point DS:DX to file spec
mov ah, 4Eh ; AH = function number
int 21h ; Find First File
pushf ; Preserve flags
push WORD PTR @data:old_dta[2] ; Pass far pointer to
push WORD PTR @data:old_dta[0] ; SetDTA procedure
call SetDTA ; Restore DTA address to orig
sub ax, ax ; Set error code
add sp, 4 ; Adjust stack
popf ; Recover flags
jnc exit ; Exit if successful match
inc ax ; Else set error code to 1
exit: ret
FindFirst ENDP
-♦-