Advertisement
Guest User

Untitled

a guest
Oct 18th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.74 KB | None | 0 0
  1. void eliminate(char * trozos[], int i){
  2. int success;
  3. char pathfinal[PATH_MAX + 1];
  4. char path[PATH_MAX];
  5. char *direccion;
  6. struct dirent *dread;
  7. DIR *dopen;
  8. char *fname;
  9. char *aux;
  10.  
  11. if (i>1) {
  12. if (strcmp(trozos[1],"-f")==0) {
  13. if (i==2) {
  14. } else {
  15. printf("- PRINCIPIO - \n");
  16. direccion = realpath(trozos[2], pathfinal);
  17. if ( (direccion !=NULL) ){
  18. if ((success=rmdir(trozos[2]))!=0){
  19. printf("- NO BORRO CARPETA VACIA - \n");
  20. dopen=opendir(direccion);
  21. if (dopen==NULL) {
  22. success = remove(direccion);
  23. printf("- BORRO ARCHIVO- \n");
  24. } else {
  25. printf("- NO ES FICHERO - \n");
  26. aux = trozos[2];
  27. while ( (dread = readdir(dopen)) != NULL ){
  28.  
  29. fname=(dread->d_name);
  30. printf("LEO EL ARCHIVO \n");
  31. printf("%s\n",fname);
  32. if((strcmp(fname, ".") == 0)
  33. || (strcmp(fname, "..") == 0)) {
  34. printf(" -salta . e .. - \n");
  35. continue; //AVANZA A LA SIGUIENTE INTERACION DEL BUCLE
  36. }
  37. printf(" CREO EL PATH ");
  38.  
  39.  
  40. snprintf (path, PATH_MAX, "%s/%s", aux, dread->d_name);
  41.  
  42. printf("%s\n",path);
  43. printf("ES LA NUEVA DIRECCION \n");
  44. trozos[2]=path;
  45. printf("%s\n",trozos[2]);
  46. printf("ES LLA NUEVA CARPETA A ELIMINAR \n");
  47. eliminate(trozos,i);
  48. printf("%s\n",trozos[2]);
  49. rmdir(aux);
  50.  
  51.  
  52.  
  53. }
  54. closedir(dopen);
  55. }
  56. }
  57. } else {
  58. perror("File not found!");
  59. }
  60. }
  61. } else {
  62. direccion = realpath(trozos[1], pathfinal);
  63. dopen=opendir(direccion);
  64. if (dopen==NULL) {
  65. success = remove(direccion);
  66. } else {
  67. success = rmdir(direccion); //Sólo se eliminará si el directorio está vacío.
  68. }
  69. }
  70.  
  71. }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement