windows C++删除非空文件夹

//add by zhuxy  递归删除文件夹
BOOL myDeleteDirectory(CString directory_path)   //删除一个文件夹下的所有内容
{   
	BOOL ret=TRUE;
	CFileFind finder;
	CString path;
	path.Format(_T("%s/*.*"),directory_path);
	BOOL bWorking = finder.FindFile(path);
	while(bWorking)
	{
		bWorking = finder.FindNextFile();
		if(finder.IsDirectory() && !finder.IsDots())
		{//处理文件夹
			myDeleteDirectory(finder.GetFilePath()); //递归删除文件夹
			RemoveDirectory(finder.GetFilePath());//只能删除空的文件夹
		}
		else
		{//处理文件
			DeleteFile(finder.GetFilePath());
		}
	}
	ret = RemoveDirectoryW(directory_path);
	return ret;
}

  

posted @ 2019-03-20 15:19  朱小勇  阅读(3625)  评论(0编辑  收藏  举报