I'm using FindNextFileW
to successfully list the files in a directory. The problem is that it references itself, current directory, with .
and parent directory with ..
. I'm trying to skip these using an if
condition but it still prints them.
Code:
int wmain() {
WIN32_FIND_DATAW data;
std::wstring dir = L"c:\\* ";
HANDLE hFind = FindFirstFileW(dir.c_str(), &data);
if (hFind != INVALID_HANDLE_VALUE) {
do {
wchar_t dot[] = L"." ;
wchar_t dotd[] = L"..";
if ( data.cFileName != dot && data.cFileName != dotd)
std::wcout << data.cFileName << std::endl;
} while (FindNextFileW(hFind, &data));
FindClose(hFind);
}
return 0;
}
As you can see, I'm trying to skip the printing of .
and ..
by using an if
condition. However, it still prints them. What am I doing wrong and how do I fix it?
EDIT:
This question is not about how wchar_t
arrays cannot be compared. That is good to know but ultimately my question is about how to skip the .
and ..
in FindNextFileW
. I have tried converting to std::wstring
but then I can define:
std::wstring dot = '.';
std:wstring dotd = '..';
But how do I check them against cFilename
?