look at this piece of source from MSDN:
They don't call FindClose if FindNextFile really failed (GetLastError()
!= ERROR_NO_MORE_FILES). Is that okay or is this a bug?
Bye
This is probably wrong code. You should always call FindClose for a
valid handle, no matter how the loop with FindNextFile ends:
HANDLE f = FindFirstFile(...);
if (f != INVALID_HANDLE_VALUE)
{
// FindNextFile loop
//...
FindClose(f);
}
I've long wondered what the neatest idiom is for FindFile. I've ended
up with this:
HANDLE hf=FindFirstFile(...);
for (BOOL b=(hf!=INVALID_FILE_HANDLE); b; b=FindNextFile(hf))
{ ...
}
if (hf!=INVALID_FILE_HANDLE) FindClose(hf);
This way, it's compact, readable, non-nested, and 'continue' and
'break' statements within the loop are robust (in the sense that they
don't need accompanying FindNext/FindClose).
--
Lucian
Alternatively you can wrap the logic in C++ class; similar to MFC's
CFindFile. Then it will be exception resistant, too.