The documentation for CFindFile states that
Nonzero if there are more files; zero if the file found is the last one in the directory or if an error occurred. To get extended error information, call the Win32 function GetLastError. If the file found is the last file in the directory, or if no matching files can be found, the GetLastError function returns ERROR_NO_MORE_FILES.
So how do I know if I have 1 file or 0 files if a call to FindNextFile returns the same value?
It seems that a call to FindFile::GetFilePath() fails (which inadvertently causes my application to crash) if zero files are found.
pLog->Log(_T("Finding files in [%s]"), 1, szFilePath);
if (!oFindFile.FindFile(szFilePath, 0))
{
pLog->Log(_T("Failed to find file in directory: [%s]"),1,szDirectory);
return false;
}
bool moreFiles = true;
while(moreFiles)
{
moreFiles = oFindFile.FindNextFile();
if (oFindFile.IsDots())
{
continue;
}
CString szFileName = oFindFile.GetFilePath();
pLog->Log(_T("Found file [%s]"), 1, szFileName);
pVector->push_back(szFileName);
}
return true;
Edit
CString szFilePath = _T("C:\documents and settings\username\desktop\*.lnk");
CString szDirectory = T("C:\documents and settings\username\desktop");