我读入一个文件路径,我要判断该路径下文件是否存在,下面的代码是否正确?如果不对,应该怎么写?
CFile file;
if(!file.Open(xmlPath,CFile::modeRead))
{
   return ;
}
file.Close();

解决方案 »

  1.   

    FileSystemObject 对象FileExists 方法
      

  2.   

    FindFirstFile看看能不能找到这个文件
      

  3.   

    WIN32_FIND_DATA fd; 
        HANDLE hFind = FindFirstFile("c:\\test.txt", &fd); 
        if ((hFind != INVALID_HANDLE_VALUE) && (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) 
        { 
         // 存在 
        } 
        FindClose(hFind);
      

  4.   

    PathFileExists Function--------------------------------------------------------------------------------Determines whether a path to a file system object such as a file or directory is valid. SyntaxBOOL PathFileExists(          LPCTSTR pszPath
    );
      

  5.   

    请问
    WIN32_FIND_DATA fd; 
        HANDLE hFind = FindFirstFile("c:\\test.txt", &fd); 
        if ((hFind != INVALID_HANDLE_VALUE) && (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) 
        { 
         // 存在 
        } 
        FindClose(hFind);
    这个是什么函数?api?
      

  6.   

    CFileFind::FindFile这个函数比较好,大部分人都这么用。
      

  7.   

    属性设置
    if (GetFileAttributes("c:\\test.txt") == FILE_ATTRIBUTE_READONLY)
    {
    SetFileAttributes(("c:\\test.txt",FILE_ATTRIBUTE_NORMAL);
    }
      

  8.   

    CFileFind::FindFile
    virtual BOOL FindFile( LPCTSTR pstrName = NULL, DWORD dwUnused = 0 );
    效率会高一些
      

  9.   

    int _access( const char *path, int mode );
    if ((_access( "A:\B\C.DEF", 0 )) != -1 )
    {
          printf( "File exists\n" );
    }
      

  10.   

    BOOL PathFileExists(LPCTSTR pszPath);
      

  11.   

    return true ;文件有效
    return false; 文件不存在
      

  12.   

    fopen,能打开就存在,打不开就不存在