设为首页 加入收藏

TOP

c++删除文件夹 源码
2015-07-20 17:13:40 来源: 作者: 【 】 浏览:2
Tags:删除 文件夹 源码

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

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);					//递归查找
		}
	}
}

?

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇BZOJ 3829 Poi2014 FarmCraft 树.. 下一篇C++ MySql实现个人电话本

评论

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

·【C语言】动态内存管 (2025-12-27 06:23:20)
·C语言中的内存管理 - (2025-12-27 06:23:16)
·C语言指南:C语言内 (2025-12-27 06:23:14)
·Redis on AWS:Elast (2025-12-27 04:19:30)
·在 Spring Boot 项目 (2025-12-27 04:19:27)