有没有此种函数,能直接确定目录的存在性?

解决方案 »

  1.   

    CFileFind f;
    if(f.Find(szPathName))
        //Directory exist.
    else
        //Not exist.
      

  2.   

    两个办法:
    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("不存在");
    }
      

  3.   

    hFile = CreateFile("c:\\somedir\\..",       //judge whether 
                                               //  directory
                                               //  c:\\somedire exists 
                    GENERIC_READ,              // open for reading 
                    FILE_SHARE_READ,           // share for reading 
                    NULL,                      // no security 
                    OPEN_EXISTING,             // existing file only 
                    FILE_ATTRIBUTE_NORMAL,     // normal file 
                    NULL);                     // no attr. template 
     
    if (hFile == INVALID_HANDLE_VALUE) 

            printf("directory doesn't exist\n");   // process error 

    else
    {      CloseHandle(hFile);
           printf("directory exists\n");
    }
      

  4.   

    WIN32_FIND_DATA FindData; 
    HANDLE hFind=FindFirstFile("C:\\Mydir",&FindData);
    if(hFind!=LPWIN32_FIND_DATA && (FindData.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY))
    {
             CloseHandle(hFind);
             /*目录在磁盘中存在*/
    }
    else
    {
             /*目录在磁盘中不存在*/
    }
      

  5.   

    粘贴错了,第三行应该是
    if(hFind!=INVALID_HANDLE_VALUE &&