home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Devil's Doorknob BBS Capture (1996-2003)
/
devilsdoorknobbbscapture1996-2003.iso
/
Dloads
/
OTHERUTI
/
MASTER-1.ZIP
/
SOURCE
/
CHAP06
/
CHAP06.LZH
/
SEARCHP.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1992-07-03
|
1KB
|
43 lines
// SEARCHP.CPP
// Demonstrates use of searchpath() to locate
// an application's own files.
#include <dir.h>
#include <iostream.h>
#include <string.h>
#include <dos.h>
int find_file( const char * filename, char * pathname )
/* Determines the location of filename by checking for
an explicit subdirectory, checking the default directory,
and then the directories specified by PATH. If found,
returns 0 and sets pathname to the subdirectory. If not
found, returns -1 */
{
char * location;
// First see if the directory was given explicitly in the filename
if (fnsplit( filename, NULL, NULL, NULL, NULL ) & DIRECTORY) {
strcpy( pathname, filename);
return 0;
}
location = searchpath( filename );
if (location == NULL)
return -1;
else {
strcpy( pathname, location );
return 0;
}
};
void main(void)
{
char pathname[MAXPATH];
// Get the program name from the command line and pass
// this to find_file() for searching.
if (find_file( _argv[0], pathname ) == 0)
cout << "File is located at " << pathname << "\n";
else
cout << "File was not found.\n";
}