RemoveDirectoryB

 

删除非空文件夹

实现过程


 

 

void RemoveDir(CString szPath)
{
    CFileFind ff;
    
    if(szPath.Right(1) != "\\")//目录的最右边需要“\”字符
        szPath += "\\";
    szPath += "*.*";
    BOOL res = ff.FindFile(szPath);
    while(res)
    {
        res = ff.FindNextFile();
        if (!ff.IsDots() && !ff.IsDirectory())
            DeleteFile(ff.GetFilePath());
        else if (ff.IsDots())
            continue;
        else if (ff.IsDirectory())//为目录
        {
            szPath = ff.GetFilePath();
            RemoveDir(szPath);
            RemoveDirectory((LPCTSTR)szPath);
        }
    }
}
    
void CSssDlg::OnOK() 
{
    CString folder="C:\\Users\\Administrator\\Desktop\\A";
    RemoveDir(folder);    
    if(RemoveDirectory((LPCTSTR)folder))
    {
      AfxMessageBox("删除成功!");
    }
}


 

 

 


 

备注

 

 

相关链接

     

 

 




原文地址:https://www.cnblogs.com/xe2011/p/2923681.html