我想判断在指定的目录下是不是存在一个指定文件名的文件,例如:判断这个文件是不是存在,strFilePath = "d:\\work\\100.jpg",怎样实现。

解决方案 »

  1.   

    两种方法:
    一、用CFileFind类;
    二、直接用CFile的OPEN函数,打开就存在,打不开,就不存在。
      

  2.   

    CFileFind finder;
       BOOL bWorking = finder.FindFile("d:\\work\\100.jpg");
       if (bWorking)
       {
          AfxMessageBox("找到");
       }
      

  3.   

    参见:
    WIN32_FIND_DATA find;
    HANDLE hFind=FindFirstFile(strFilePath,&find);
    if (hFind==INVALID_HANDLE_VALUE) 
    {
    MessageBox(NULL,_T("not found!"),NULL,MB_OK);
    return 0;
    }
      

  4.   

    用_access()函数最简单,需要引用direct.h头文件不是查查msdn.
    if(_access(szfilepath,0) == -1)//表示不存在
    {}
      

  5.   

    CFileFind finder;
       BOOL bWorking = finder.FindFile("d:\\work\\100.jpg");
       if (bWorking)
       {
          AfxMessageBox("找到");
       }
    推荐这个。
      

  6.   

    int _access( const char *path, int mode );
    这个好用
      

  7.   

    if(_access(路径,0)!=0)
    {
       //不存在
    }
      

  8.   

    FindFirstFileThe FindFirstFile function searches a directory for a file whose name matches the specified file name. FindFirstFile examines subdirectory names as well as file names.
      

  9.   

    BOOL bRet=PathFileExists(strFileName);
    Header: shlwapi.h 
    Import library: shlwapi.lib 
    enjoy uself