删除文件夹 – 青春部落,流年似水 http://www.youthtribe.com 青春是一场远行,总记不起来时的路。 Tue, 16 Sep 2014 14:20:43 +0000 zh-CN hourly 1 https://wordpress.org/?v=6.1.6 删除文件夹 – 青春部落,流年似水 http://www.youthtribe.com/archives/1350 http://www.youthtribe.com/archives/1350#respond Tue, 16 Sep 2014 14:20:43 +0000 http://www.youthtribe.com/?p=1350 vc++[mfc]递归删除文件夹及其里边的文件

void DeleteDirectory(LPCTSTR path)
{
	CFileFind findfile;
	CString str;
	str=path;
	if(str.Right(1)!="\\")
		str.Format("%s\\*.*",path);
	else
		str.Format("%s*.*",path);
	BOOL find=findfile.FindFile(str);

	while(find)
	{
		find=findfile.FindNextFile();
		if(findfile.IsDirectory())
		{
			if(!findfile.IsDots())
			{

				DeleteDirectory(findfile.GetFilePath());
			}
		}
		else
		{
			DeleteFile(findfile.GetFilePath());
		}
	}
	findfile.Close();
	if(!RemoveDirectory(path))
	{
		DWORD ret=::GetLastError();
		CString strerr;
		strerr.Format("%d",ret);
		MessageBox(strerr,"错误代码",MB_OK);
	}
}
]]>
http://www.youthtribe.com/archives/1350/feed 0