Jump to content

DosFindClose: Difference between revisions

From EDM2
Created page with "==Description== Closes the handle to a find request; that is, ends a search. ==Syntax== <PRE> #define INCL_DOSFILEMGR #include <os2.h> HDIR hDir; /* Directory search ..."
 
Ak120 (talk | contribs)
No edit summary
Line 7: Line 7:
#include <os2.h>
#include <os2.h>


HDIR     hDir;  /* Directory search handle. */
HDIR   hDir;  /* Directory search handle. */
APIRET   ulrc;  /* Return Code. */
APIRET ulrc;  /* Return Code. */


ulrc = DosFindClose(hDir);
ulrc = DosFindClose(hDir);
</PRE>


</PRE>
==Parameters==
==Parameters==
; hDir (HDIR) - input : Directory search handle.
;hDir (HDIR) - input : Directory search handle.


The handle previously associated with a DosFindFirst function by the system, or used with a DosFindNext directory search function.
The handle previously associated with a DosFindFirst function by the system, or used with a DosFindNext directory search function.
Line 21: Line 21:


DosFindClose returns one of the following values:
DosFindClose returns one of the following values:
*0 NO_ERROR
*6 ERROR_INVALID_HANDLE


* 0    NO_ERROR
* 6    ERROR_INVALID_HANDLE
==Remarks==
==Remarks==
Once DosFindClose is issued, any subsequent DosFindNext issued for the closed handle (hDir) fails unless an intervening DosFindFirst specifying the handle is issued.  
Once DosFindClose is issued, any subsequent DosFindNext issued for the closed handle (hDir) fails unless an intervening DosFindFirst specifying the handle is issued.  
Line 81: Line 81:
     return NO_ERROR;
     return NO_ERROR;
  }
  }
</PRE>


</PRE>
==Related Functions==
==Related Functions==
* [[OS2 API:CPI:DosFindFirst|DosFindFirst]]
* [[DosFindFirst]]
* [[OS2 API:CPI:DosFindNext|DosFindNext]]
* [[DosFindNext]]
 


[[Category:The OS/2 API Project]]
[[Category:The OS/2 API Project]]

Revision as of 16:05, 1 October 2016

Description

Closes the handle to a find request; that is, ends a search.

Syntax

#define INCL_DOSFILEMGR
#include <os2.h>

HDIR    hDir;  /* Directory search handle. */
APIRET  ulrc;  /* Return Code. */

ulrc = DosFindClose(hDir);

Parameters

hDir (HDIR) - input
Directory search handle.

The handle previously associated with a DosFindFirst function by the system, or used with a DosFindNext directory search function.

Return Code

ulrc (APIRET) - returns

DosFindClose returns one of the following values:

  • 0 NO_ERROR
  • 6 ERROR_INVALID_HANDLE

Remarks

Once DosFindClose is issued, any subsequent DosFindNext issued for the closed handle (hDir) fails unless an intervening DosFindFirst specifying the handle is issued.

Example Code

This example lists all the normal files that are in the directory from where the example is invoked.

 #define INCL_DOSFILEMGR   /* File Manager values */
 #define INCL_DOSERRORS    /* DOS error values */
 #include <os2.h>
 #include <stdio.h>

 int main (VOID) {
    HDIR          hdirFindHandle = HDIR_CREATE;
    FILEFINDBUF3  FindBuffer     = {0};      /* Returned from FindFirst/Next */
    ULONG         ulResultBufLen = sizeof(FILEFINDBUF3);
    ULONG         ulFindCount    = 1;        /* Look for 1 file at a time    */
    APIRET        rc             = NO_ERROR; /* Return code                  */

    rc = DosFindFirst( "*.*",                /* File pattern - all files     */
                       &hdirFindHandle,      /* Directory search handle      */
                       FILE_NORMAL,          /* Search attribute             */
                       &FindBuffer,          /* Result buffer                */
                       ulResultBufLen,       /* Result buffer length         */
                       &ulFindCount,         /* Number of entries to find    */
                       FIL_STANDARD);        /* Return level 1 file info     */

    if (rc != NO_ERROR) {
       printf("DosFindFirst error: return code = %u\n",rc);
       return 1;
    } else {
       printf ("%s\n", FindBuffer.achName);   /* Print file name             */
    } /* endif */

    /* Keep finding the next file until there are no more files */
    while (rc != ERROR_NO_MORE_FILES) {
       ulFindCount = 1;                      /* Reset find count.            */

       rc = DosFindNext(hdirFindHandle,      /* Directory handle             */
                        &FindBuffer,         /* Result buffer                */
                        ulResultBufLen,      /* Result buffer length         */
                        &ulFindCount);       /* Number of entries to find    */

       if (rc != NO_ERROR && rc != ERROR_NO_MORE_FILES) {
          printf("DosFindNext error: return code = %u\n",rc);
          return 1;
       } else {
          printf ("%s\n", FindBuffer.achName);    /* Print file name */
       }
    } /* endwhile */

    rc = DosFindClose(hdirFindHandle);    /* Close our directory handle */
    if (rc != NO_ERROR) {
       printf("DosFindClose error: return code = %u\n",rc);
       return 1;
    }
    return NO_ERROR;
 }

Related Functions