Yeah so my previous post was correct.
Start by just printing the files without recursion to see what I mean:
1 2 3 4 5 6 7 8
|
WIN32_FIND_DATAA ffd;
HANDLE hfile=FindFirstFileA("C:\\Program Files\\*.*", &ffd);
do
{
cout << ffd.cFileName << endl;
}while(FindNextFileA(hfile,&ffd));
FindClose(&ffd);
|
Notice how you get two extra directories here:
"."
and
".."
Windows puts these in every directory (except for top-level directories, apparently). "." is this directory, and ".." is the parent directory.
If you are iterating over all files...
you want to ignore these entries. So you'll have to explicitly look for them and skip over them.
Also:
You're using the wrong character type. FindFirstFile takes TCHAR strings. If you are using regular char strings, you should be using:
FindFirstFileA
FindNextFileA
WIN32_FIND_DATAA
(notice how they all end with and extra 'A'). Details here:
http://www.cplusplus.com/forum/windows/106683/
Also, remember to close your handles with FindClose when you're done with them.
And consistent indenting really makes it easier to read the code.