Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void eliminate(char * trozos[], int i){
- int success;
- char pathfinal[PATH_MAX + 1];
- char path[PATH_MAX];
- char *direccion;
- struct dirent *dread;
- DIR *dopen;
- char *fname;
- if (i>1) {
- if (strcmp(trozos[1],"-f")==0) {
- if (i==2) {
- } else {
- printf("- llego1 - \n");
- direccion = realpath(trozos[2], pathfinal);
- if ( (direccion !=NULL) ){
- printf("- llego2 - \n");
- dopen=opendir(direccion);
- if (dopen==NULL) {
- success = remove(direccion);
- } else {
- printf("- deberia llegar - \n");
- while ( (dread = readdir(dopen)) != NULL ){
- fname=(dread->d_name);
- printf("- no sé - \n");
- if((strcmp(fname, ".") == 0)
- || (strcmp(fname, "..") == 0)) {
- printf(" -salta . e .. - \n");
- continue; //AVANZA A LA SIGUIENTE INTERACION DEL BUCLE
- }
- printf("- no llego -");
- success = remove(fname);
- snprintf (path, PATH_MAX, "%s/%s", trozos[2], dread->d_name);
- printf("%s\n",fname);
- trozos[2]=path;
- printf("%s\n",trozos[2]);
- eliminate(trozos,i);
- }
- closedir(dopen);
- }
- } else {
- perror("File not found!");
- }
- }
- } else {
- direccion = realpath(trozos[1], pathfinal);
- dopen=opendir(direccion);
- if (dopen==NULL) {
- success = remove(direccion);
- } else {
- success = rmdir(direccion); //Sólo se eliminará si el directorio está vacío.
- }
- }
- if (success == -1) {
- printf("File couldn't be removed! \n");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement