Hello i have to write in c (linux) function to remove all file from directory i cannot use remove function or execl only unlink and rmdir.
i used readdir :
int removefile( char *file)
{
struct dirent * entry;
DIR *dir;
char *p;
char *d;
char *tmp;
dir = opendir(file);
errno =0;
strcpy( d, file );//kopiowanie file do p
strcat( d, "/" );//dodawanie /
strcpy(tmp,d);//kopiowanie d do tmp
strcpy(p,d); //kopiowanie d do p
while((entry=readdir(dir)) !=NULL)
{
if(entry->d_type==DT_REG)
{
strcat(d,entry->d_name);
int a=unlink(d);
strcpy(d,tmp);
}
else if(entry->d_type==DT_DIR)
{
strcat(p,entry->d_name);
int b=removefile(p);
int c=rmdir(p);
strcpy(p,tmp);
}
}
closedir(dir);
return 0;
}
but i get Memory Access Violation thx