Hi. I'm trying to access the file names of all the files in a folder. I am trying to use FindFirstFile to do this. However, I'm having some issues.
Code:
void TestFunction()
{
string directoryPath = "C:\\TestFolder\\";
WIN32_FIND_DATA FindFileData;
HANDLE hFind = INVALID_HANDLE_VALUE;
hFind = FindFirstFile(directoryPath.c_str(), &FindFileData);
//cout << FindFileData.cFileName << endl;
if(hFind != INVALID_HANDLE_VALUE)
{
cout << FindFileData.cFileName << endl;
cout << "Test" << endl;
}
else
{
cout << "Fail" << endl;
}
}
Currently, "Fail" will print. If I try to output the file name before the if statement, it prints jibberish. I've looked over a bunch of examples, but I can't seem to figure out what the problem is.
In this current example, I had to change my project settings to "Use Multi-Byte Character Set" instead of "Use Unicode character set". If I leave it as "Use Unicode character set", I change the following in my code:
Code:
hFind = FindFirstFile(LPCWSTR(directoryPath.c_str()), &FindFileData);
This will also print "Fail". If I output the file name before the if statement, it outputs: 0012FC18
Any ideas?