在创建一个目录之前要确认该目录是否存在,如果不存在,在用户确认后创建该目录。

解决方案 »

  1.   

    CFileFind FileFind;
    if(FileFind.FindFile(m_strTempFile))
    {
    ;
    }
    else
    {
    while(ilength !=-1) {


    CString strDirectory =m_strTempFile.Left(ilength);

    if(!FileFind.FindFile(strDirectory,0))
    if(!CreateDirectory(strDirectory,NULL))
    {
    ::MessageBeep(MB_ICONHAND);
    MessageBox(IMAGE_LOADER_CREATEDIRETORY_ERR, NULL, MB_OK + MB_ICONSTOP + MB_SYSTEMMODAL);
    }
    ilength = m_strTempFile.Find("\\",ilength+1);
    }
    }
      

  2.   

    int _access( const char *path, int mode );
    // mode Value Checks File For 
    // 00:  Existence only 
    // 02:  Write permission 
    // 04:  Read permission 
    // 06:  Read and write permission // Example:
    if (_access("PathName", 0 )) != -1) {
        // ...
    }
      

  3.   

    用不着File Find这么麻烦
    正如 kimryo(一切皆有可能)所说的,用PathFileExists就行了。
      

  4.   

    慢了一步,呵呵,就是PathFileExists函数最方便了。
      

  5.   

    I use this
    DWORD dwAttr = GetFileAttributes( strRoot );
    if ( dwAttr == -1 )
    {
    //如果用户指定的路径不存在则要生成一个
    _________________________________________________
    PathFileExists_________________________________________________
    // Example:
    if (_access("PathName", 0 )) != -1) {
        // ...
    }_________________________________________________
    FileFind.FindFile(m_strTempFile
    _________________________________________________
    还有没有其它方法
      

  6.   

    1、
        CFileFind f;
        if(f.FindFile("c:\\temp"))
            AfxMessageBox("存在");
            //Directory exist.
        else
            AfxMessageBox("不存在");
            //Not exist.2、
        if(_access("c:\\temp", 0) == 0){
            AfxMessageBox("存在");
        }
        else{
            AfxMessageBox("不存在");
        }