mov cx, Attributes ;attributes to search for
mov dx, seg FileName
mov ds, dx
mov dx, offset FileName ;ds:dx points to file or directory name(s)
mov ah, 4Eh ;Find First File
int 21h
jc error_handler ;carry set means error
Find First File (Function 4Eh) searches a directory for the first file or directory whose name and attributes match the specified name and attributes.
Attributes
Specifies the attributes to search for. This parameter can be a combination of the following attributes:
Value | Meaning |
ATTR_NORMAL (0000h) | File can be read from or written to. |
ATTR_READONLY (0001h) | File can be read from, but not written to. |
ATTR_HIDDEN (0002h) | File or directory is hidden and does not appear in a directory listing. |
ATTR_SYSTEM (0004h) | File or directory is a system file or directory. |
ATTR_VOLUMEID (0008h) | Filename is the volume label of media in specified drive. |
ATTR_DIRECTORY (0010h) | Filename identifies a directory, not a file. |
FileName
Points to a zero-terminated ASCII string that specifies the file or directory to search for. The name must be a valid MS-DOS filename or directory name and can include wildcards.
If the function is successful, the carry flag is clear and the file information is copied as a FILEINFO structure to the current disk transfer address (DTA). Otherwise, the carry flag is set and the AX register contains an error value, which may be one of the following:
Value | Name |
0002h | ERROR_FILE_NOT_FOUND |
0003h | ERROR_PATH_NOT_FOUND |
0012h | ERROR_NO_MORE_FILES |
If the DTA has not been explicitly set by Set Disk Transfer Address (Function 1Ah), MS-DOS uses the default DTA, offset 80h, in the program segment prefix (PSP).
If a program specifies any combination of ATTR_SYSTEM, ATTR_HIDDEN, and ATTR_DIRECTORY, this function returns normal files as well as the specified files. The program must examine the attribute contained in the DTA to determine the type of file found.
The FILEINFO structure that contains the file information has the following form:
FILEINFO STRUC
fiReserved db 21 dup (?) ;reserved
fiAttribute db ? ;attributes of file found
fiFileTime dw ? ;time of last write
fiFileDate dw ? ;date of last write
fiSize dd ? ;file size
fiFileName db 13 dup (?) ;filename and extension
FILEINFO ENDS
For a full description of the FILEINFO structure, see Chapter 3, “File System.”
Function 1Ah Set Disk Transfer Address
Function 4Fh Find Next File