void DeleteDirectory(CString strPath)
{
CFileFind tempFind;
TCHAR sTempFileFind[MAX_PATH] = { 0 };
wsprintf(sTempFileFind, _T("%s\\*.*"), strPath);
BOOL IsFinded = tempFind.FindFile(sTempFileFind);
while (IsFinded)
{
IsFinded = tempFind.FindNextFile();
if (!tempFind.IsDots())
{
TCHAR sFoundFileName[200] = { 0 };
_tcscpy(sFoundFileName, tempFind.GetFileName().GetBuffer(200));
if (tempFind.IsDirectory())
{
TCHAR sTempDir[200] = { 0 };
wsprintf(sTempDir, _T("%s\\%s"), strPath, sFoundFileName);
DeleteDirectory(sTempDir); //删除文件夹下的文件
RemoveDirectory(sTempDir); //移除空文件
}
else
{
TCHAR sTempFileName[200] = { 0 };
wsprintf(sTempFileName, _T("%s\\%s"), strPath, sFoundFileName);
DeleteFile(sTempFileName);
}
}
}
tempFind.Close();
}
int main()
{
CString m_path;
m_path = "C:\\Users\\YangJingLong\\Desktop\\staistic\\staistic\\data\\";
DeleteDirectory(m_path);
}