Hi!
The following function gives me an application error when I pass a filename (or wildchards) in searchFor that doesn't exist. (For example, I set path to "C:" and searchFor to "*.txt" but there's no txt-File in C:\ )
How can I avoid that? Why does the while-loop run nevertheless there's no such file?
Code:
BOOL FillTreeViewWithFileNames(HWND hwndTree, LPSTR path, LPSTR searchFor, UINT level)
{
HANDLE hf;
WIN32_FIND_DATA FindFileData;
CHAR searchmask[260]="";
strcpy(searchmask, path);
strcat(searchmask, "\\");
strcat(searchmask, searchFor);
if(!FindFirstFile(searchmask, &FindFileData)) return 0;
hf = FindFirstFile(searchmask, &FindFileData);
if( (FindFileData.dwFileAttributes != FILE_ATTRIBUTE_DIRECTORY) && (strcmp(FindFileData.cFileName,".")) && (strcmp(FindFileData.cFileName,"..")))
{
AddItemToTree(hwndTree, FindFileData.cFileName, level);
}
while(FindNextFile(hf, &FindFileData))
{
if( (FindFileData.dwFileAttributes != FILE_ATTRIBUTE_DIRECTORY) && (strcmp(FindFileData.cFileName,".")) && (strcmp(FindFileData.cFileName,"..")))
{
AddItemToTree(hwndTree, FindFileData.cFileName, level);
}
}
FindClose(hf);
return 1;
}