Your code works fine if you exclude the direcories named "." and ".." from the search.
The body of your first while loop should look like this :
if(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
// Exclude "." and ".." directories
if (_tcscmp(FindFileData.cFileName, _T(".")) != 0 &&
_tcscmp(FindFileData.cFileName, _T("..")) != 0)
{
// found a subdirectory; recurse into it
PathCombine(szFullPattern, lpFolder, FindFileData.cFileName);
FindFilesRecursively(szFullPattern, lpFilePattern);
}
}
The "." directory is the current directory and if you recurse into that you will never get out of recursion, because you will scan the same directory over and over again until the stack is full.
The ".." directory is the directory "above" the current directory and if you scan that you will also run into an infinite recursion for the same reason as stated above.
BTW you can see those directories by using the dir
command in a cmd window.