Given a file specification in the form of an ASCIIZ string, searches the default or specified directory on the default or specified drive for the first matching file.
Call with:
AH = 4EH
CX = search attribute (bits may be combined)
Bit(s) Significance (if set)
0 read-only
1 hidden
2 system
3 volume label
4 directory
5 archive
6—15 reserved (0)
DS:DX = segment:offset of ASCIIZ pathname
Returns:
If function successful (matching file found)
Carry flag = clear
and search results returned in current disk transfer area as follows:
Byte(s) Description 00H—14H reserved (0) 15H attribute of matched file or directory 16H—17H file time bits 00H—04H = 2-second increments (0—29) bits 05H—0AH = minutes (0—59) bits 0BH—0FH = hours (0—23) 18H—19H file date bits 00H—04H = day (1—31) bits 05H—08H = month (1—12) bits 09H—0FH = year (relative to 1980) 1AH—1DH file size 1EH—2AH ASCIIZ filename and extension
If function unsuccessful (no matching files)
Carry flag = set
AX = error code
Notes:
This function assumes that the DTA has been previously set by the program with Int 21H Function 1AH to point to a buffer of adequate size.
The * and ? wildcard characters are allowed in the filename. If wildcard characters are present, this function returns only the first matching filename.
If the attribute is 0, only ordinary files are found. If the volume label attribute bit is set, only volume labels will be returned (if any are present). Any other attribute or combination of attributes (hidden, system, and directory) results in those files and all normal files being matched.
Example:
Find the first .COM file in the directory \MYDIR on drive C.
fname db 'C:\MYDIR\*.COM',0
dbuff db 43 dup (0) ; receives search results
.
.
.
; set DTA address
mov ah,1ah ; function number
mov dx,seg dbuff ; result buffer address
mov ds,dx
mov dx,offset dbuff
int 21h ; transfer to MS-DOS
; search for first match
mov ah,4eh ; function number
mov cx,0 ; normal attribute
mov dx,seg fname ; address of filename
mov ds,dx
mov dx,offset fname
int 21h ; transfer to MS-DOS
jc error ; jump if no match
.
.
.