用SerchPath(..)就可以了。
如下例,检查d:\mydir\myavi.avi是否存在。
if (SearchPath("d:\\mydir","myavi.avi",NULL,MAX_PATH,filepath,NULL) ) 
{ Play(filepath,hWnd); }

解决方案 »

  1.   

    最好的办法:
     BOOL FileExists(CString name)
    {
    OFSTRUCT ofn;
    if(OpenFile((LPCSTR)name,&ofn,OF_EXIST)!=HFILE_ERROR)
    return TRUE;
    else
    return FALSE;
    }
      

  2.   

    在msdn里面查一下createfile这个函数,如果文件存在,会返回fileExist的错误
      

  3.   

    HANDLE CreateFile(
      LPCTSTR lpFileName,                         // file name
      DWORD dwDesiredAccess,                      // access mode
      DWORD dwShareMode,                          // share mode
      LPSECURITY_ATTRIBUTES lpSecurityAttributes, // SD
      DWORD dwCreationDisposition,                // how to create
      DWORD dwFlagsAndAttributes,                 // file attributes
      HANDLE hTemplateFile                        // handle to template file
    );
      

  4.   

    CreatFile这个API函数,其中有一个参数DWORD dwCreationDisposition就是用来指定对存在的文件采取哪种措施,当文件不存在时采用哪种措施的.有一个值是:OPEN_EXISTING,打开文件如果文件不存在,则函数调用失败.