⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 a.txt

📁 删除夹的封装函数
💻 TXT
字号:
可以指定删除文件的类型,或除指定类型不删除,或删除所有文件
调用类型:

  	DeleteDirectoryOrFile("d:\\Test",0,"");			//删除所有文件
	DeleteDirectoryOrFile("d:\\Test",1,".dll");			//删除.dll文件
	DeleteDirectoryOrFile("d:\\Test",2,".jctsq");		//不删除.jctsq文件

	参数: CString strFilePath	//文件夹路径
 	参数: UINT nDelType		//删除方式
	参数: CString nTypeName	//删除类型
	返回: TRUE (删除成功) FALSE(删除失败)

BOOL DeleteDirectoryOrFile(CString strFilePath, UINT nDelType, CString nTypeName)
{
	CFileFind tempFind;
	CString strSelPath;
	strSelPath = strFilePath + "\\*.*";
	BOOL SelResult = tempFind.FindFile(strSelPath);

	while(SelResult)
	{
		SelResult = tempFind.FindNextFile();
		if(!tempFind.IsDots())
		{
			if(tempFind.IsDirectory())
			{
				CString strFindPath = strFilePath + "\\"+ tempFind.GetFileName();
				DeleteDirectoryOrFile(strFindPath,nDelType,nTypeName);

			}else
			{
				CString strFindName = tempFind.GetFilePath();
				if(nDelType == 0 && nTypeName.IsEmpty())		//删除所有文件
				{
					DeleteFile(strFindName); 
				}
				if(nDelType == 1 && !nTypeName.IsEmpty())		//删除指定文件类型
				{
					strFindName.MakeLower();
					nTypeName.MakeLower();
					int pos = strFindName.Find(nTypeName);
					if(pos !=-1)
					{
						DeleteFile(strFindName);
					}
				}
				if(nDelType == 2 && !nTypeName.IsEmpty())		//不删除指定文件类型
				{
					strFindName.MakeLower();
					nTypeName.MakeLower();
					int pos = strFindName.Find(nTypeName);
					if(pos ==-1)
					{
						DeleteFile(strFindName);
					}
				}
			}
		}
	}
	tempFind.Close();
	if(!RemoveDirectory(strFilePath)) 
  	  { 
       		 return FALSE; 
   	 } 
	return TRUE;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -