void my_rm(char* argv)
{
DIR *dp=opendir(argv);
while(1)
{
struct dirent *tp =readdir(dp);
if(NULL==tp)
{
break;
}
if(strcmp(tp->d_name,".")== 0 || strcmp(tp->d_name,"..")== 0)
{
continue;
}
if(tp->d_type==DT_REG)
{
char *pathname=malloc(1000);
snprintf(pathname,1000,"%s/%s",argv,tp->d_name);
printf("%s\n",pathname);
unlink(pathname);
}
else if(tp->d_type==DT_DIR)
{
char *pathname=malloc(1000);
snprintf(pathname,1000,"%s/%s",argv,tp->d_name);
printf("%s\n",pathname);
my_rm(pathname);
rmdir(pathname);
}
}
rmdir(argv);
}
int main(int argc,char *argv[])
{
for(int i=1;argv[i]!=NULL;i++)
{
my_rm(argv[i]);
}
//printf("%s\n",tp->d_name);
return 0;
}