File search problem
-
I have some problem in my code .Due to my inexpereicne iam not able to solve it . HANDLE hFile; LPWIN32_FIND_DATA FileData; hFile=FindFirstFile(str,FileData); if(hFile==INVALID_HANDLE_VALUE) { FindClose(hFile); return FALSE; } else { FindClose(hFile); AfxMessageBox("File Does Exists "); return TRUE; } This is a MFC application .This code is part of CMainFrame class in a fucntion .When the function returns TRUE ,the application crashes .Help me out please
-
I have some problem in my code .Due to my inexpereicne iam not able to solve it . HANDLE hFile; LPWIN32_FIND_DATA FileData; hFile=FindFirstFile(str,FileData); if(hFile==INVALID_HANDLE_VALUE) { FindClose(hFile); return FALSE; } else { FindClose(hFile); AfxMessageBox("File Does Exists "); return TRUE; } This is a MFC application .This code is part of CMainFrame class in a fucntion .When the function returns TRUE ,the application crashes .Help me out please
The answer doesn't immediately spring to mind but, two points which may help... 1) I'm not sure that you have to call
FindClose()
when the handle returned is INVALID_HANDLE_VALUE. 2) Have you tried using theaccess()
function declared in . This can be used to check for the existence of a file too. -
I have some problem in my code .Due to my inexpereicne iam not able to solve it . HANDLE hFile; LPWIN32_FIND_DATA FileData; hFile=FindFirstFile(str,FileData); if(hFile==INVALID_HANDLE_VALUE) { FindClose(hFile); return FALSE; } else { FindClose(hFile); AfxMessageBox("File Does Exists "); return TRUE; } This is a MFC application .This code is part of CMainFrame class in a fucntion .When the function returns TRUE ,the application crashes .Help me out please
hi there if you only want to check if the file is existing you can do that like that : CString csMyFile = "c:\\temp\\some.file.dat"; CFileStatus statusFile; BOOL bExists = CFile::GetStatus( csMyFile, statusFile ); return( bExists ); But i guess the crash is a result of that : HANDLE hFile; LPWIN32_FIND_DATA FileData; hFile=FindFirstFile(str,FileData); You should not only pass a pointer to FindFirstFile(..). It must be a pointer to an existing WIN32_FIND_DATA-struct !!! If you only pass a pointer to "SomeWhereInMemory" and FindFirstFile starts writing data about an existing file ... it writes to "SomeWhereInMemory" .... and that no good idea ! look at the VC++ MSDN-Help about FindFirstFile : pFindFileData : Pointer to the WIN32_FIND_DATA structure that receives information about the found file ... so write it that way : WIN32_FIND_DATA FileData; hFile=FindFirstFile(str,&FileData); and i think it will work .... (without GPF).