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 >
C/C++ Source or Header  |  1992-07-03  |  1KB  |  43 lines

  1. // SEARCHP.CPP
  2. // Demonstrates use of searchpath() to locate
  3. // an application's own files.
  4. #include <dir.h>
  5. #include <iostream.h>
  6. #include <string.h>
  7. #include <dos.h>
  8.  
  9. int find_file( const char * filename, char * pathname )
  10. /* Determines the location of filename by checking for
  11.    an explicit subdirectory, checking the default directory,
  12.    and then the directories specified by PATH.  If found,
  13.    returns 0 and sets pathname to the subdirectory.  If not
  14.    found, returns -1 */
  15. {
  16.   char * location;
  17.  
  18.   // First see if the directory was given explicitly in the filename
  19.   if (fnsplit( filename, NULL, NULL, NULL, NULL ) & DIRECTORY) {
  20.     strcpy( pathname, filename);
  21.     return 0;
  22.   }
  23.   location = searchpath( filename );
  24.   if (location == NULL)
  25.     return -1;
  26.   else {
  27.     strcpy( pathname, location );
  28.     return 0;
  29.   }
  30. };
  31.  
  32. void main(void)
  33. {
  34.   char pathname[MAXPATH];
  35.  
  36.   // Get the program name from the command line and pass
  37.   // this to find_file() for searching.
  38.   if (find_file( _argv[0], pathname ) == 0)
  39.     cout << "File is located at " << pathname << "\n";
  40.   else
  41.     cout << "File was not found.\n";
  42.  
  43. }