home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / mavcl130.zip / MAVDRSR.CPP < prev    next >
C/C++ Source or Header  |  1995-08-15  |  2KB  |  76 lines

  1. /*  File: MAVDRSR.CPP      Updated: Tue Aug 15 15:53:36 1995
  2. Copyright (c) Fabrizio Aversa
  3. ===========================================================*/
  4. #define INCL_DOS
  5. #include <os2.h>
  6.  
  7. #include <ctype.h>
  8. #include <iostream.h>
  9. #include <istring.hpp>
  10.  
  11. #include <mavdrsr.hpp>
  12.  
  13. DirServ::DirServ(IString & str1):
  14. strPath(str1)
  15. {
  16.    rc= 0;
  17.    iCount= 0;
  18.    FindHandle= 0;
  19. }
  20.  
  21. INT DirServ::errorCode()
  22. {
  23.    return rc;
  24. }
  25.  
  26. IString DirServ::getNext()
  27. {
  28.    ULONG FindCount= 1;
  29.    FILEFINDBUF3  FindBuffer;
  30.    IString strRet;
  31.    
  32.    switch(iCount) {
  33.       
  34.       case (-1):
  35.       strRet= "";
  36.       return strRet;
  37.       break;
  38.       
  39.       case(0):
  40.       
  41.       FindHandle= 0x0001;
  42.       
  43.       rc = DosFindFirst((PSZ)strPath,     /* File pattern */
  44.       &FindHandle, /* Directory search handle */
  45.       0,     /* Search attribute */
  46.       (PVOID) &FindBuffer,   /* Result buffer */
  47.       sizeof(FindBuffer),  /* Result buffer length */
  48.       &FindCount,  /* # of entries to find */
  49.       FIL_STANDARD); /* Return level 1 file info */
  50.       
  51.       break;
  52.       
  53.       default:
  54.       
  55.       rc = DosFindNext(FindHandle, /* Directory handle */
  56.       (PVOID) &FindBuffer,  /* Result buffer */
  57.       sizeof(FindBuffer), /* Result buffer length */
  58.       &FindCount);        /* Number of entries to find */
  59.       
  60.       break;
  61.       
  62.    }
  63.    
  64.    if(rc) {
  65.       strRet= "";
  66.       DosFindClose(FindHandle);
  67.       iCount= -1;
  68.    } else {
  69.       iCount++;
  70.       strRet= FindBuffer.achName;
  71.    }
  72.    
  73.    return strRet;
  74. }
  75.  
  76.