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.
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.
string directoryPath = "C:\\TestFolder\\";
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;
cout << "Fail" << endl;
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:
This will also print "Fail". If I output the file name before the if statement, it outputs: 0012FC18
hFind = FindFirstFile(LPCWSTR(directoryPath.c_str()), &FindFileData);