Introduction
I
Created this to show you how to delete all the files and subfolders in a selected folder including subfolders. It's
very easy to understand and it's all by using the MFC (CFileFind, with
some API functions)
void RecursiveDelete(CString szPath)
{
CFileFind ff;
CString path = szPath;
if(path.Right(1) != "\\")
path += "\\";
path += "*.*";
BOOL res = ff.FindFile(path);
while(res)
{
res = ff.FindNextFile();
if (!ff.IsDots() && !ff.IsDirectory())
DeleteFile(ff.GetFilePath());
else if (ff.IsDirectory())
{
path = ff.GetFilePath();
RecursiveDelete(path);
RemoveDirectory(path);
}
}
}