home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ool_main.zip / ool / source / xfilefi.cpp < prev    next >
C/C++ Source or Header  |  1998-03-27  |  2KB  |  72 lines

  1. #include "XFileFi.h"
  2. #include "xfileinf.h"
  3.  
  4. #include <string.h>
  5.  
  6.  
  7. /*@
  8. @class XFileFind
  9. @parent XObject
  10. @type overview
  11. @symbol _
  12. */
  13.  
  14. /*@ XFileFind :: XFileFind(const char *m, const LONG o)
  15. @group constructors/destructors
  16. @remarks Construct a XFileFind-instance (do not forget to call the destructor)
  17. @parameters char * mask for the files to find(e.g. "*.EXE" )
  18. */
  19. XFileFind :: XFileFind(const char *m)
  20. {
  21.    init = TRUE;
  22.    mask = m;
  23.    dir = HDIR_SYSTEM;
  24. }
  25.  
  26.  
  27. /*@ XFileFind::Find(XString * string, XFileInfo*)
  28. @group find files
  29. @remarks After you have created an instance you can start to find files. Find()
  30. copy the filename found to the given bufer and returns TRUE, it returns FALSE if no file is found.
  31. @parameters
  32. <t '°' c=2>
  33. °XString * °buffer to hold the filename
  34. °XFileInfo*  °buffer for file-info
  35. </t>
  36. @returns BOOL
  37. @updated _
  38. */
  39. BOOL XFileFind::Find(XString * string, XFileInfo*info)
  40. {
  41.    LONG res;
  42.    ULONG count = 1;
  43.  
  44.    memset( &info->buffer, 0, sizeof(info->buffer));
  45.    if (init)
  46.    {
  47.       res = DosFindFirst((PSZ) (char *) mask, &dir, FILE_NORMAL|FILE_HIDDEN|FILE_SYSTEM|FILE_DIRECTORY, &info->buffer, sizeof(info->buffer), &count, 1);
  48.       init = FALSE;
  49.    }
  50.    else
  51.       res = DosFindNext(dir, &info->buffer, sizeof(info->buffer), &count);
  52.    if (res == 0)
  53.    {
  54.       memcpy(string->GetBuffer(info->buffer.cchName), info->buffer.achName, info->buffer.cchName);
  55.       string->ReleaseBuffer( info->buffer.cchName);
  56.       return TRUE;
  57.    }
  58.    else
  59.       return FALSE;
  60. }
  61.  
  62.  
  63. /*@ XFileFind :: ~XFileFind()
  64. @group constructors/destructors
  65. @remarks Destroys a XFileFind-instance. Never forget to call the destructor!
  66. */
  67. XFileFind :: ~XFileFind()
  68. {
  69.    DosFindClose(dir);
  70. }
  71.  
  72.