Im checking if FindNextFile() return value is zero or GetLastError() != ERROR_NO_MORE_FILES but it still goes into the while() loop.
What am i doing wrong?
Actually its working ok as long as there are more than one file but when there is
only one it gets printed two times.
Code:#include <windows.h>
#include <iostream>
using namespace std;
int main()
{
char Data[256] = "C:\\*.txt";
WIN32_FIND_DATA data;
HANDLE hFile = FindFirstFileA(Data, &data);
if(hFile != INVALID_HANDLE_VALUE)
{
strcpy(Data, data.cFileName);
cout << "1: " << Data << endl;
}
while(FindNextFile(hFile, &data)!= 0 || GetLastError() != ERROR_NO_MORE_FILES);
{
strcpy(Data, data.cFileName);
cout << "2: " << Data << endl;
}
}