parameter format : e:\temp\test.txt

解决方案 »

  1.   

    使用_access( "e:\\temp\\test.txt", 0),返回0表示存在,否则不存在。
      

  2.   

    FILE *fp = fopen( "e:\\temp\\test.txt", "r" );
    if( fp == NULL ) MessageBox( "e:\\temp\\test.txt 不存在!" );
    else fclose( fp );
      

  3.   

    CString strPath("C:\\a.txt");
    HANDLE hFile = NULL;

    hFile= CreateFile(
    strPath,
    GENERIC_ALL,
    FILE_SHARE_READ,
    NULL,
    OPEN_EXISTING,//判定文件是否存在 FILE_ATTRIBUTE_NORMAL,
    NULL);

    DWORD dwErr = GetLastError();
    if (dwErr == ERROR_FILE_NOT_FOUND)
    {
      AfxMessageBox("FILE_NOT_FOUND");
    }if (hFile)
      CloseHandle(hFile);
      

  4.   

    或者:
    CFileFind find;
    int result=find.FindFile("C:\\aaa.txt");
    if(result==0)
    {
        AfxMessageBox("文件不存在");
    }
    else
    {
        AfxMessageBox("文件存在");
    }
      

  5.   

    #include <afx.h>
    CFileFind objFind ;
    objFind.FindFile( strFileName ) ;
      

  6.   

    if ((_access(path,0))==-1)//文件不存在
    {
    }
    else
                       {}
      

  7.   

    个人觉得还是用FindFile更好些,其他的方法文件可能存在只是可能被独占打开
      

  8.   

    1.PathFileExists
    2.打开文件,看返回信息
    3._access()
    ..
      

  9.   

    如 sans(sans)  所说, 我就不多说了