Sunyanfeng00000

导航

 

删除文件夹 递归

bool RemoveDir(const char* szFileDir)
{
	std::string strDir = szFileDir;
	if (strDir.at(strDir.length() - 1) != '\\')
		strDir += '\\';
	WIN32_FIND_DATAA wfd;
	HANDLE hFind = FindFirstFileA((strDir + "*.*").c_str(), &wfd);
	if (hFind == INVALID_HANDLE_VALUE)
		return false;
	do
	{
		if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
		{
			if (strcmp(wfd.cFileName, ".") != 0 &&
				strcmp(wfd.cFileName, "..") != 0)
				RemoveDir((strDir + wfd.cFileName).c_str());
		}
		else
		{
			DeleteFileA((strDir + wfd.cFileName).c_str());
		}
	} while (FindNextFileA(hFind, &wfd));
	FindClose(hFind);
	RemoveDirectoryA(szFileDir);
	return true;
}
posted on 2020-09-01 19:20  Sunyanfeng00000  阅读(53)  评论(0)    收藏  举报