c++删除文件夹 源码

2015-07-20 17:13:40 ? 作者: ? 浏览: 3

由于没有找到直接用于删除文件夹的函数,所以自己写了一个。

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());
			}
		}www.2cto.com
		else if (findfile.IsDots()) 
		{
			continue;
		}
		else if (findfile.IsDirectory())							//如果是目录
		{
			DelFile(findfile.GetFilePath(),name);					//递归查找
		}
	}
}

?

-->

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: