以下经过调试成功的方法:
CFileFind fileFinder;
BOOL bWorking = fileFinder.FindFile("sample.txt");
while (bWorking)
{
bWorking = fileFinder.FindNextFile(); if (!fileFinder.IsDirectory () && !fileFinder.IsSystem () &&
!fileFinder.IsHidden () && !fileFinder.IsTemporary ())
{
                       // the file "sample.txt" is found in current dir.
}
}

fileFinder.Close();
将samlpe.txt改成你的文件名就OK

解决方案 »

  1.   

    FindFirstFile如结构体中的size没负值就不存在.
      

  2.   

    也可以采用OpenFile方式来确定文件是否存在
      

  3.   

    简单:
    用尝试打开的方法不就行了???如果在当前目录下能打开,文件就在呗。
    打开不成功,自然就不存在。没有必要去CFileFind
      

  4.   

     1.
    CFile file;
    if(file.open(filename,CFile::modeRead))
      cout<<"the specified file is exist"<<endl;
    else
      cout<<"the specified file is not exist"<<endl;
    2.
    HANDLE hfile;    WIN32_FIND_DATA fd;
    if((hfile=FindFirstFile(colorstring,&fd))==INVALID_HANDLE_VALUE)
     cout<<"the specified file is exist"<<endl;
    else
      cout<<"the specified file is not exist"<<endl;
      

  5.   

    to billbord(billy) and nhcf() :
      我试过你们的方法,都可以,但我发现
     1.    CFileFind    fileFinder;
        BOOL        bWorking = fileFinder.FindFile("*.*");
        while (bWorking)
        {
            bWorking = fileFinder.FindNextFile();
             CString filename=fileFinder.GetFileName();
      

  6.   

       谢谢各位高手。
    to billbord(billy) and nhcf() :
       我试过你们的方法都可以,但当我用如下两方法想得到某目录中所有文件时,却发现
       前两次循环得到的文件名都为:"."和".." ,请问怎么回事。
     1.    CFileFind    fileFinder;
        BOOL        bWorking = fileFinder.FindFile("*.*");
        while (bWorking)
        {
            bWorking = fileFinder.FindNextFile();
             CString filename=fileFinder.GetFileName();
         }
      2      
           HANDLE hfile;    WIN32_FIND_DATA fd;
         CString folder,curdirfile;
         GetCurrentDirectory(folder);
         curdirfile=folder+"*.*";
    hfile=FindFirstFile(curdirfile,&fd);
    if((hfile!=INVALID_HANDLE_VALUE)&&(bfind==TRUE))
     {
        CString filename=fd.cfilename;
        bfind=FindNextFile(hfile,&fd);
      }
        
    else
      cout<<"the specified file is not exist"<<endl;
           
      

  7.   

    每个目录都包含这两个东东
    “.”代表该级目录
    “..”代表上级目录
    在DOS里不就有了吗
      

  8.   

     ForStudy(羡慕大家)还在吗? 
      

  9.   

    查找*.*包括.和..,这是目录。
    正确的操作方法应该加上如下判断:
    //------------------------------------------------------------
    // start to search all the file under the given directory
    //------------------------------------------------------------ 
    CFileFind fileFinder;
    BOOL bWorking = fileFinder.FindFile("*.*");
    while (bWorking)
    {
      bWorking = fileFinder.FindNextFile();  if (!fileFinder.IsDirectory () && !fileFinder.IsSystem () &&
      !fileFinder.IsHidden () && !fileFinder.IsTemporary ())
      {
         找到的文件名:fileFinder.GetFileTitle ()
      }
    }fileFinder.Close();