BOOL DeleteDirectory(CString DirName,BOOL bRemoveRootDir)
{
CFileFind tempFind;
CString csZRootDir;
csZRootDir.Format(L"%s\\*.*",DirName.GetBuffer(0));
BOOL IsFinded=(BOOL)tempFind.FindFile(csZRootDir.GetBuffer(0));
while(IsFinded)
{
IsFinded=(BOOL)tempFind.FindNextFile();
if(!tempFind.IsDots())
{
CString csFileName;
csFileName.Format(L"%s",tempFind.GetFileName().GetBuffer(0));
if(tempFind.IsDirectory())
{
CString tmp;
tmp.Format(L"%s\\%s",DirName.GetBuffer(0),csFileName.GetBuffer(0));
DeleteDirectory(tmp,TRUE);
}
else
{
CString tmp;
tmp.Format(L"%s\\%s",DirName,csFileName.GetBuffer(0));
DeleteFile(tmp.GetBuffer(0));
}
}
}
tempFind.Close();
if (bRemoveRootDir)
{
if(!RemoveDirectory(DirName))
{
//LogRecord(TRUE,_T("remove directory failed! %s \r\n"),DirName);
return FALSE;
}
}
return TRUE;
}
c++ 删除文件夹
最新推荐文章于 2024-09-09 00:30:00 发布