问题如题目:
我是这样做的
         CFile mfile;
if(mfile.Open("test.dat",CFile::modeRead,NULL)==0)
{
AfxMessageBox("file test.dat is not exist",NULL,0);
return;
}
mfile.Close();但是这样做开销太大(进行磁盘访问操作),有没有好的方法?

解决方案 »

  1.   

    titilima(李马) 的这个函数好用:
    BOOL FileExists(LPCTSTR lpszFileName)
    {
      WIN32_FIND_DATA wfd;
      BOOL bRet;
      HANDLE hFind;
      hFind = FindFirstFile(lpszFileName, &wfd);
      bRet = hFind != INVALID_HANDLE_VALUE;
      FindClose(hFind);
      return bRet;
    }
      

  2.   

    BOOL PathFileExists(LPCTSTR pszPath
    );Header shlwapi.h 
    Import library shlwapi.lib 
      

  3.   

    DoesFileExist(BSTR bstrFileName,  /* [out, retval] */ VARIANT_BOOL* retVal);
      

  4.   

    CString sPath;
    sPath="*****";
    CFileFind  fFind;
    if(fFind.FindFile(lpszFileName))
        //找到
      

  5.   

    汗,OPEN & CLOSE 操作似乎是有额外开销,傻了:(
      

  6.   

    #include  <io.h>
    #include  <stdio.h>
    #include  <stdlib.h>void main( void )
    {
       /* Check for existence */
       if( (_access( "ACCESS.C", 0 )) != -1 )
       {
          printf( "File ACCESS.C exists\n" );
          /* Check for write permission */
          if( (_access( "ACCESS.C", 2 )) != -1 )
             printf( "File ACCESS.C has write permission\n" );
       }
    }