Listing 5: Function Recurse

void DirWalk::Recurse() throw(runtime_error) {
    HANDLE hFind;
    mDepth++; // if Recurse has been called,
              // then we're one level lower
 
    hFind=FindFirstFile(mSearchSpec,&mFindData);

    mFoundAnother=(hFind!=INVALID_HANDLE_VALUE);
    while(mFoundAnother) {
        mSize = mFindData.nFileSizeLow; // set the file size
        mSizeHigh = mFindData.nFileSizeHigh;
        mFA   = mFindData.dwFileAttributes;
        mIsDir= mFA.IsDirectory();
        // set up the time objects for this file
        mCreationTime.NewTime(&mFindData.ftCreationTime);
        mLastAccessTime.NewTime(&mFindData.ftLastAccessTime);
        mLastWriteTime.NewTime(&mFindData.ftLastWriteTime);
        if(!mIsDir) {
            FoundFile(); // announce each file (but not dirs, yet)
        }
        mFoundAnother=FindNextFile(hFind, &mFindData); // next one
    }
    if(hFind != INVALID_HANDLE_VALUE) {
        if (FindClose(hFind) == FALSE) throw runtime_error(
            "DirWalk::Recurse().Problem closing hFind.");
    }

    // OK, we've listed all the files of interest.
    // Now, we go into subdirectories and list those if we need to
    if(mRecurse) {
        hFind=FindFirstChildDir();
        mFoundAnother=(hFind != INVALID_HANDLE_VALUE);
        while(mFoundAnother) {
            mFA=mFindData.dwFileAttributes; // same game as above
            mCreationTime.NewTime(&mFindData.ftCreationTime);
            mLastAccessTime.NewTime(&mFindData.ftLastAccessTime);
            mLastWriteTime.NewTime(&mFindData.ftLastWriteTime);
            mSize=mFindData.nFileSizeLow;
            mSizeHigh=mFindData.nFileSizeHigh;
            // go into subdirectory
            if(SetCurrentDirectory(mFindData.cFileName) == TRUE) {
                if(mListSubDirs) FoundFile(); // announce subdir name
                Recurse();       //list files in the subdirectory now
                if(SetCurrentDirectory("..") == FALSE)
                  throw runtime_error(
                    "DirWalk::Recurse(). Prob chnging to parnt dir");
            }

            mFoundAnother=FindNextChildDir(hFind); //next subdir
        }
        if(hFind != INVALID_HANDLE_VALUE) {
            if(FindClose(hFind) == FALSE)
                throw runtime_error(
                    "DirWalk::Recurse().Problem closing hFind(2).");
        }
    }
    mDepth--;           // we're returning to the parent's depth now
} //void DirWalk::Recurse()
//End of File