2.1.10.16 FindNextFile


Description

The FindNextFile function continues a file search from a previous call to the FindFirstFile function.

Syntax

BOOL FindNextFile( HANDLE hFindFile, WIN32_FIND_DATAA * lpFindFileData )

Parameters

hFindFile
[input] Search handle returned by a previous call to the FindFirstFile function.
lpFindFileData
[output] Pointer to the WIN32_FIND_DATAA structure that receives information about the found file or subdirectory. The structure can be used in subsequent calls to FindNextFile to refer to the found file or directory.

Return

If the function succeeds, return true; else return false.

Examples

EX1

int FindNextFile_ex1()
{
    // case1: List all file under c:
    string strPath = "c:\\*.*";
    dir(strPath);
    return 1;
}
// a DOS dir command
// can type into ScriptWindow "dir c:\*.*", for example.
//
void dir(string strFile)
{
    WIN32_FIND_DATAA    find;
    HANDLE    hFile;

    //out_str(strFile);
    int    nCount = 0;
    
    if((hFile=FindFirstFile(strFile,&find)) != INVALID_HANDLE_VALUE)
    {
        out_str(find.cFileName);
        nCount++;
        while(FindNextFile(hFile,&find))
        {
            out_str(find.cFileName);
            nCount++;
        }
        printf("%d files found\n",nCount);
        FindClose(hFile);        // must close  the handle
    }
    else
        printf("%s: file(s) not found\n",strFile);
}

Remark

See Also

FindFirstFile, FindClose

Header to Include

origin.h

Reference