Пример #1
0
bool Utils::rmdir(const std::string &path)
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
    return IOSUtils::rmdir(path);
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
	bool result = true;
	
	struct dirent *dirp;
	DIR *dp;
	if ((dp = ::opendir(path.c_str())) == NULL)
	{
		return false;
	}
	while (result && ((dirp = ::readdir(dp)) != NULL))
	{
		if (strcmp(dirp->d_name, ".") == 0 || strcmp(dirp->d_name, "..") == 0)
		{
			continue;
		}
		std::string subpath(path);
		subpath += "/";
		subpath += dirp->d_name;
		struct stat substat;
		if (::stat(subpath.c_str(), &substat) < 0)
		{
			result = false;
			break;
		}

		//rm all of files under the specified dir recursively
		if (S_ISDIR(substat.st_mode))
		{
			result = rmdir(subpath);
		}
		else if (S_ISREG(substat.st_mode))
		{
			result = rmFile(subpath);
		}
	}
	if (::closedir(dp) < 0)
	{
		return false;
	}
	//now the dir is empty
	if (::rmdir(path.c_str()) < 0)
	{
		return false;
	}
	
    return result;
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
	return WP8Utils::getInstance().rmdir(path);
#endif    
}
Пример #2
0
void beforeRemove(char x[])
{
    int i=0,j=0,len=0,biao=0;
    char tou[CurPathMax],wei[20];
    len=strlen(x);
    for(i=0;i<len;i++)
        if(x[i]=='/')
            biao=i;
    i=0;
    if(biao==0)
        strcpy(tou,CurPath);
    else
    {
        for(;i<biao;i++)
            tou[j++]=x[i];
        tou[j]=0;
        i++;
    }
    j=0;
    for(;i<len;i++)
        wei[j++]=x[i];
    wei[j]=0;
    rmFile(tou,wei);
}
Пример #3
0
/*------------------------------------------------------------------------
 * lfsControl - Provide control functions for a local file system 
 *------------------------------------------------------------------------
 */
devcall	lfsControl (
	 struct dentry	*devptr,	
	 int32	func,			/* a control function		*/
	 int32	arg1,			/* argument #1			*/
	 int32	arg2			/* argument #2			*/
	)
{
	int retval;
	switch(func)
	{
		case LF_CTL_FORMAT:
			{
				retval=	lfscreate(LF_DISK_DEV,arg1,arg2);							
				return retval;
			}
		case LF_CTL_MKDIR:
			{
				retval = mkDir((char*)arg1);
				return retval;
			}
		case LF_CTL_RMDIR:
			{
				retval = rmDir((char*)arg1);
				return retval;
			}
		case LF_CTL_DEL:
			{
				retval = rmFile((char*)arg1);
				return retval;
			}
		default:
			return SYSERR;
	}
	return OK;	

}