如题

解决方案 »

  1.   

    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.   

    你可以用CFileFind类去查找,不过我一般用CFile去打开文件,成功则文件存在,否则不存在CFile file;
    if(file.Open(filename, CFile::modeRead))
    {
       //file exist
       file.Close();
    }
    else
    {
       //file not exist
    }
    当然如果该文件被别的程序非共享打开的话,文件打开也会失败
      

  3.   

    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;
    }
    这个能判断目录吗?
      

  4.   

    int check_path(char *path)
    {
        if(_chdir(path) == 0)
           return 0; // dir is exist.
        if(fopen(path,"r") != 0)
           return 0; // file is exist.
        return -1; // path is not exist.
    }