c++刪除文件夾 源碼

由於沒有找到直接用於刪除文件夾的函數,所以自己寫了一個。

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);					//遞歸查找
		}
	}
}


 

發佈了52 篇原創文章 · 獲贊 40 · 訪問量 15萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章