Find the file with the specified attributes or find the next file with the specified attributes.
#include <dos.h>
#include <errno.h>
unsigned _dos_findfirst( char *filename, unsigned attrib,
struct _find_t *fileinfo );
unsigned _dos_findnext( struct _find_t *fileinfo );
filename | Target filename | |
attrib | Target attributes | |
fileinfo | File-information buffer |
The _dos_findfirst routine uses system call 0x4E to return information about the first instance of a file whose name and attributes match filename and attrib.
The filename argument may use wildcards (* and ?). The attrib argument can be any of the following manifest constants:
Constant | Meaning |
_A_ARCH | Archive. Set whenever the file is changed, and cleared by the DOS BACKUP command. | |
_A_HIDDEN | Hidden file. Cannot be found with the DOS DIR command. Returns information about normal files as well as about files with this attribute. | |
_A_NORMAL | Normal. File can be read or written without restriction. | |
_A_RDONLY | Read-only. File cannot be opened for writing, and a file with the same name cannot be created. Returns information about normal files as well as about files with this attribute. | |
_A_SUBDIR | Subdirectory. Returns information about normal files as well as about files with this attribute. | |
, | ||
_A_SYSTEM | System file. Cannot be found with the DOS DIR command. Returns information about normal files as well as about files with this attribute. | |
_A_VOLID | Volume ID. Only one file can have this attribute, and it must be in the root directory. |
Multiple constants can be combined (with the OR operator), using the vertical-bar (|) character.
If the attrib argument to either of these functions is _A_RDONLY,
_A_HIDDEN, _A_SYSTEM, or _A_SUBDIR, the function also returns
any normal attribute files that match the filename argument. That is, a normal
file does not have a read-only, hidden, system, or directory attribute.
Information is returned in a _find_t structure, defined in DOS.H. The _find_t structure contains the following elements:
Element | Description |
char reserved[21] | Reserved for use by DOS |
char attrib | Attribute byte for matched path |
unsigned wr_time | Time of last write to file |
unsigned wr_date | Date of last write to file |
long size | Length of file in bytes |
char name[13] | Null-terminated name of matched file/directory, without the path |
The formats for the wr_time and wr_date elements are in DOS format and are not usable by any other C run-time function. The time format is shown below:
Bits | Contents |
0–4 | Number of 2-second increments (0–29) |
5–10 | Minutes (0–59) |
11–15 | Hours (0–23) |
The date format is shown below:
Bits | Contents |
0–4 | Day of month (1–31) |
5–8 | Month (1–12) |
9–15 | Year (relative to 1980) |
Do not alter the contents of the buffer between a call to _dos_findfirst and a subsequent call to the _dos_findnext function. Also, the buffer should not be altered between calls to _dos_findnext.
The _dos_findnext routine uses system call 0x4F to find the next name, if any, that matches the filename and attrib arguments specified in a prior call to _dos_findfirst. The fileinfo argument must point to a structure initialized by a previous call to _dos_findfirst. The contents of the structure will be altered as described above if a match is found.
If successful, both functions return 0. Otherwise, they return the DOS error code and set errno to ENOENT, indicating that filename could not be matched.
Standards:None
16-Bit:DOS, QWIN, WIN, WIN DLL
32-Bit:None
/* DFIND.C: This program finds and prints all files in the current directory
* with the .c extension.
*/
#include <stdio.h>
#include <dos.h>
void main( void )
{
struct _find_t c_file;
/* find first .c file in current directory */
_dos_findfirst( “*.c”, _A_NORMAL, &c_file );
printf( “Listing of .c files\n\n” );
printf( “File: %s is %ld bytes\n”, c_file.name, c_file.size );
/* find the rest of the .c files */
while( _dos_findnext( &c_file ) == 0 )
printf( “File: %s is %ld bytes\n”, c_file.name, c_file.size );
}
Listing of .c files
File: CHDIR.C is 524 bytes
File: SIGFP.C is 2674 bytes
File: MAX.C is 258 bytes
File: CGETS.C is 577 bytes
File: FWRITE.C is 1123 bytes