linux 递归删除多级目录

代码如下:

#include
int CParseJson::emptyDir(const char* destDir)
{
	int ret = 0;
	DIR* dp = NULL;
	struct dirent* entry = NULL;
	struct stat statbuf;
	
	if ((dp = opendir(destDir)) == NULL)
	{
		LOG4CXX_ERROR(logger, "cannot open directory, errno = "<d_name) || ".." == string(entry->d_name))
		{
			continue;
		}
		
		string dirT = string(destDir) + "/" + string(entry->d_name);
		lstat(dirT.c_str(), &statbuf);
		//if (!S_ISREG(statbuf.st_mode))
		if(!(statbuf.st_mode & S_IFDIR))
		{
			string temp = string(destDir) + "/" + string(entry->d_name);
			ret = remove(temp.c_str());
			if(ret)
			{
				LOG4CXX_ERROR(logger, "remove file fail, errno = "<

你可能感兴趣的:(C/C++,linux)