I’m trying to get FindFileFirst() windows API call to work and it’s totally failing on every attempt. I’ve tried ., C:\*.*, .txt, C:\.txt and yet it doesn’t even iterate down directory names. Not sure what to try anymore. I’m getting ERROR_FILE_NOT_FOUND 2 (0x2) back when I call GetLastError(). Thanks for any help you can give.
HANDLE hFind;
LPWIN32_FIND_DATA FindFileData;
hFind = FindFirstFile("*.*", &FindFileData);
if(hFind == INVALID_HANDLE_VALUE)
{
printf("\nFindFirstFile failed (%u)\n",GetLastError());
return;
}
do
{
if(FindFileData->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
if(FindFileData->cFileName[0] != '.')
continue;
else
searchDir(makePath(path, FindFileData->cFileName));
}
printf("Found %s %s\n",
FindFileData->dwFileAttributes,FindFileData->cFileName);
FindClose(hFind);
}
while(FindNextFile(hFind, &FindFileData));
FindClose(hFind);
LPWIN32_FIND_DATA FindFileData;
You are using FindFileData pointer without allocating memory to it.
use this way.. (“remove LP”)
WIN32_FIND_DATA FindFileData; // this will use stack memory
then refer to members like FindFileData.dwFileAttributes instead of FindFileData->dwFileAttributes