Assembly Language Help (alang.hlp) (Table of Contents; Topic list)
FindFirst
 Map                                       Up Contents Index Back
────────────────────────────────────────────────────────────────────────────
 
;* FindFirst - Finds first entry in given directory matching specification.
;*
;* Shows:   DOS Function - 4Eh (Find First File)
;*          Instructions - 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
OldDta  FPVOID  ?                       ; Storage for old DTA address
 
        .CODE
 
FindFirst PROC USES ds,
        Attr:WORD,
        Fspec:PBYTE,
        Finfo:PFILEINFO
 
        ; Get current DTA address, pass address of pointer to hold value
        INVOKE  GetDTA,
                ADDR OldDta
 
        mov     cx, Attr                ; Load CX with file attribute
 
        ; Set DTA address, pass pointer to structure
        INVOKE  SetDTA,
                Finfo
 
        LoadPtr ds, dx, Fspec           ; Point DS:DX to file spec
        mov     ah, 4Eh                 ; AH = function number
        int     21h                     ; Find First File
 
        pushf                           ; Preserve flags
 
        ; Restore DTA address, pass pointer
        INVOKE  SetDTA,
                OldDta
 
        sub     ax, ax                  ; Set error code
        popf                            ; Recover flags
        .IF     carry?
        inc     ax                      ; Set error code to 1
        .ENDIF
        ret
 
FindFirst ENDP
                                    -♦-