void RemoveFolder(PCTSTR szDirPath
)
{
CString
strDir(szDirPath
);
CString
strDest(strDir
);
strDest
+= _T("\\*.*");
_tfinddata_t findData
;
intptr_t handle
= _tfindfirst(strDest
, &findData
);
if (handle
!= -1)
{
do
{
if ((_tcscmp(findData
.name
, _T(".")) == 0) || (_tcscmp(findData
.name
, _T("..")) == 0))
continue;
CString strFound
;
strFound
.Format(_T("%s\\%s"), (PCTSTR
)strDir
, findData
.name
);
if (findData
.attrib
& _A_SUBDIR
)
{
RemoveFolder(strFound
);
}
else
{
if (findData
.attrib
& _A_RDONLY
)
{
::SetFileAttributes(strFound
, FILE_ATTRIBUTE_NORMAL
);
}
::DeleteFile(strFound
);
}
} while (_tfindnext(handle
, &findData
) == 0);
}
_findclose(handle
);
::SetFileAttributes(strDir
, FILE_ATTRIBUTE_NORMAL
);
::RemoveDirectory(strDir
);
}
转载请注明原文地址:https://tech.qufami.com/read-5175.html