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 / FINDDEMO.CPP < prev    next >
C/C++ Source or Header  |  1992-07-02  |  1KB  |  44 lines

  1. // FINDDEMO.CPP
  2. // This program demonstrates the use of the
  3. // findfirst() and findnext() functions to
  4. // display a directory listing.
  5. #include <dir.h>
  6. #include <iostream.h>
  7. #include <string.h>
  8. #include <dos.h>
  9.  
  10. void searchdirectory (char * directory )
  11. {
  12.   char tempdirectory[MAXPATH];
  13.   int last_one;
  14.   struct ffblk fileinfo;
  15.  
  16.   strcpy (tempdirectory, directory);
  17.   // Note use of wildcard in next line; see text for details.
  18.   strcat( tempdirectory, "*.*" );
  19.   last_one = findfirst( tempdirectory, &fileinfo,  FA_NORMAL + FA_DIREC
  20.                          + FA_RDONLY );
  21.   while (!last_one) {
  22.     if (fileinfo.ff_name[0] != '.') {
  23.       cout << directory << fileinfo.ff_name;
  24.       if (fileinfo.ff_attrib & FA_DIREC) {
  25.     cout << "  <DIRECTORY>\n";
  26.     strcpy( tempdirectory, directory );
  27.     strcat( tempdirectory, fileinfo.ff_name );
  28.     strcat( tempdirectory, "\\" );
  29.     searchdirectory( tempdirectory );
  30.       };
  31.       cout << "\n";
  32.    };
  33.    last_one = findnext( &fileinfo );
  34.   };
  35. };
  36.  
  37. void main( void )
  38. {
  39.  
  40.   // Set starting directory here
  41.   searchdirectory( "C:\\" );
  42.  
  43. };
  44.