由於沒有找到直接用於刪除文件夾的函數,所以自己寫了一個。
void CDeleteDlg::DelFile(CString path,CString name)
{
CString strtemp;
if (path.Right(1) != "\\") //判斷路徑是否以\結尾
strtemp.Format("%s\\*.*",path); //設置通配符
else
strtemp.Format("%s*.*",path); //設置通配符
CFileFind findfile;
BOOL bfind = findfile.FindFile(strtemp); //查找文件
while (bfind) //循環查找
{
bfind = findfile.FindNextFile(); //查找下一個文件
if(!findfile.IsDots() && !findfile.IsDirectory())
{
CString str = findfile.GetFileName();
int index = str.ReverseFind('.');
if(str.Right(str.GetLength()-index) == name)
{
DeleteFile(findfile.GetFilePath());
}
}
else if (findfile.IsDots())
{
continue;
}
else if (findfile.IsDirectory()) //如果是目錄
{
DelFile(findfile.GetFilePath(),name); //遞歸查找
}
}
}