如题

解决方案 »

  1.   

    BOOL IsFileExist(LPCTSTR pszFile)
    {
    BOOL bExist = TRUE;
    HANDLE hFind;
    WIN32_FIND_DATA dataFind;
    BOOL bMoreFiles = TRUE;
    hFind = FindFirstFile(pszFile,&dataFind);
    if(hFind== INVALID_HANDLE_VALUE)
    {
    bExist = FALSE;
    }
    FindClose(hFind);
    return bExist;
    }
      

  2.   

    http://community.csdn.net/Expert/topic/3037/3037094.xml?temp=.3460047
      

  3.   

    FILE fp;
    fp=fopen(szFileName,"r");//szFileName是文件名
    if(fp == NULL)
       TRACE("文件不存在!");
      

  4.   

    _access(文件名,0)如果返回值为-1,表示不存在
    否则,存在
      

  5.   

    给你一段我的代码
    BOOL CConfigDlg::IsDevFileExist(CString devname)
    {
    CFileFind tempFind;
    CString path;
    CString str, str1; path = g_strDevicePath + "*.*";  /* 得到当前目录 */ BOOL bIsFinded =(BOOL)tempFind.FindFile(path); /* 判断目录下是否为空 */ while(bIsFinded)
    {
    bIsFinded = (BOOL)tempFind.FindNextFile();
    if( !tempFind.IsDots() )
    {
    str = tempFind.GetFileName();
    str1.Format( "%s%s", devname, ".txt" );
    if( str != str1 )
    continue;
    else
    {
    tempFind.Close();
    return true;
    }
    }
    }

    tempFind.Close();
    return false;
    }
      

  6.   

    GetStatus( LPCTSTR lpszFileName, CFileStatus& rStatus );The static version gets the status of the named file and copies the filename to m_szFullName. This function obtains the file status from the directory entry without actually opening the file. It is useful for testing the existence and access rights of a file.
      

  7.   

    最简单的函数调用:if(_access("filename", 0)==-1)
    {
       TRACE("File not exit.");
    }
      

  8.   

    CFileFind file;
    BOOL bFind=file.FindFile(".\\*.ini");
    if(!bFind) MessageBox("缺少配置文件!","提示");
      

  9.   

    如果是Win32编程推荐用CreateFile
    它里面有一个参数dwCreationDisposition专门就是为这个设计的,而且如果存在可以立即获得文件句柄,立即进入下一步操作
    dwCreationDisposition :
    OPEN_EXISTING Opens the file. The function fails if the file does not exist. 
                  For a discussion of why you should use OPEN_EXISTING for devices, 
                  see Res