#include <dirent.h>


void delete_path(const char* path){

	__android_log_print(ANDROID_LOG_INFO, COM_HSDI_LOG_TITLE, "delete_path %s", path);

	DIR *pDir = NULL;
	struct dirent *dmsg;
	char szFileName[128];
	char szFolderName[128];

	strcpy(szFolderName, path);
	strcat(szFolderName, "/%s");
	if ((pDir = opendir(path)) != NULL)
	{
		__android_log_print(ANDROID_LOG_INFO, COM_HSDI_LOG_TITLE, "open dir success");
		// 遍历目录并删除文件
		while ((dmsg = readdir(pDir)) != NULL)
		{
			__android_log_print(ANDROID_LOG_INFO, COM_HSDI_LOG_TITLE, "do while %s-->%s", szFileName);
			if (strcmp(dmsg->d_name, ".") != 0 && strcmp(dmsg->d_name, "..") != 0)
			{
				sprintf(szFileName, szFolderName, dmsg->d_name);
				__android_log_print(ANDROID_LOG_INFO, COM_HSDI_LOG_TITLE, "do remove %s", szFileName);
				string tmp = szFileName;
				//如果是文件夹,名称中不包含"."
				if (tmp.find(".") == -1){
					delete_path(szFileName);
				}
				remove(szFileName);
			}
		}
	}

	__android_log_print(ANDROID_LOG_INFO, COM_HSDI_LOG_TITLE, "open dir over");

	if (pDir != NULL)
	{
		closedir(pDir);
	}
}

Logo

更多推荐