How can I locate my program’s important files (databases, configuration files, and such)?
DOS provides a pair of functions that enable you to search a directory for a file of any type. You can search for files that are normal, archive, hidden, system, read-only, directories, and even volume labels. Following is a short example of how to search for a particular file in the current directory:
#include <stdio.h>
#include <dos.h>
void main( void )
{
struct _find_t myFile;
_dos_findfirst( “MYFILE.INI”, _A_NORMAL, &myFile );
while(_dos_findnext(&myFile) == 0)
printf(“Found file %s of size %s\n”, myFile.name,
myFile.size);
}
This example demonstrates how the _dos_findfirst() and _dos_findnext() functions work. You can go into a directory and use these two functions as shown to find a file of a particular name. These functions also allow the * and ? wildcards. They will return every file in a directory if you use *.* as the filename. To find every file on the hard drive, place the preceding example code in a recursive function that will go into subdirectories to search for the specified file.
Cross Reference:
None.
No comments:
Post a Comment