CFileFind myfile;
BOOL flag=myfile.FindFile("c:\\window\\h.txt);
if(flag)
   MessageBox("Find the file !");
else
   MessageBox("No file !");

解决方案 »

  1.   

    XiangDong(木头) 
    列目录或者打开该文件,检查返回值或错误类型 这两种方法,好像速度比ydogg(灰毛兔)的方法更慢些。还有其它的方法了吗? 如没有就结帖子了。
      

  2.   

    BOOL IsFileExist(const char *szFileName)
    {
       CFileStatus stat;
       if(CFile::GetStatus(szFileName,stat))
       return TRUE;
       else 
       return FALSE;
    }
      

  3.   

    CFile file ;
    if(!file.Open(m_PathFileName, CFile::modeRead))
    {
    不存在;
    }
    else
    file.Close() ;
    哈哈哈,最笨的方法了!
      

  4.   

    WhiteWaterBlueSky(疯狂数码) 这方法不错。
      

  5.   

    WIN32_FIND_DATA fd;
    HANDLE hFile;
    CString FilePath = "c:\\windows\\h.txt"; //file pathhFile = FindFirstFile(FilePath,&fd);if (hFile !=INVALID_HANDLE_VALUE ) //file existelse //file don't exist
         
      

  6.   

    ColdWolf(天边流星) 的方法技术含量好高。佩服。
      

  7.   

    GetFileAttribute,失败就表示没有
      

  8.   

    jeff_hunter(PandaLee) 回复于2001-8-15 16:05:25   
    GetFileAttribute,失败就表示没有  OK!jeff_hunter(PandaLee) 你的思维好开阔.DWORD GetFileAttributes(
      LPCTSTR lpFileName   // pointer to the name of a file or directory
    );
    If the function succeeds, the return value contains the attributes of the specified file or directory.
    If the function fails, the return value is 0xFFFFFFFF
      

  9.   

    同 leslin(leslin)
    最简单的用 ANSI 的 access, 可判断文件是否存在,是否可读,是否可写......别的办法都没这个好吧
      

  10.   

    _access(pPath, 00);

    OpenFile(lpFileName, NULL, OF_EXIST);
      

  11.   

    我觉得打开-〉失败 就不能直接判断不存在的,有可能存在其他的问题呢?
    用CFile::CFile或CFile::Open的时候,如果失败,它们就抛出CFileException
    ,这个CFileException::m_cause就有CFileException::fileNotFound   ,这才能判断。
    附失败原因:
    CFileException::none   No error occurred.
    CFileException::generic   An unspecified error occurred.
    CFileException::fileNotFound   The file could not be located.
    CFileException::badPath   All or part of the path is invalid.
    CFileException::tooManyOpenFiles   The permitted number of open files was exceeded.
    CFileException::accessDenied   The file could not be accessed.
    CFileException::invalidFile   There was an attempt to use an invalid file handle.
    CFileException::removeCurrentDir   The current working directory cannot be removed.
    CFileException::directoryFull   There are no more directory entries.
    CFileException::badSeek   There was an error trying to set the file pointer.
    CFileException::hardIO   There was a hardware error.
    CFileException::sharingViolation   SHARE.EXE was not loaded, or a shared region was locked.
    CFileException::lockViolation   There was an attempt to lock a region that was already locked.
    CFileException::diskFull   The disk is full.
    CFileException::endOfFile   The end of file was reached. 
    与大家共同探讨!
      

  12.   

    lbqsv(vc_lover) 这个问题却实值的注意。
    平时我们做的时候,都略过了这个问题。把打不开文件等于不存在了。