Advertisement
Guest User

Untitled

a guest
Oct 18th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.55 KB | None | 0 0
  1.  
  2. void recursiveL(char * direccionInicial, int flag){
  3.     char * direccion;
  4.     char path[PATH_MAX];
  5.     char pathfinal[PATH_MAX+1]; //HACER CONDICION SALIR EN CASO DE QUE LLEGUE AL FINAL DE LA CADENA
  6.     struct stat buf;
  7.     DIR *dopen;
  8.     struct dirent *dread;
  9.        
  10.    
  11.     direccion = realpath(direccionInicial, pathfinal);
  12.  
  13.         if (direccion != NULL) {
  14.          lstat(pathfinal, &buf);
  15.          info(direccionInicial);
  16.           if (!(S_ISREG(buf.st_mode))){
  17.             if (flag != 1) {
  18.                 dopen = opendir(pathfinal);
  19.                 if (dopen != NULL){
  20.                 while ( ((dread = readdir(dopen))!=NULL) ){
  21.                  if((strcmp(dread->d_name, ".") == 0)
  22.                      || (strcmp(dread->d_name, "..") == 0)) {
  23.                          continue; //AVANZA A LA SIGUIENTE INTERACION DEL BUCLE
  24.                      } 
  25.                      snprintf (path, PATH_MAX, "%s/%s", direccionInicial, dread->d_name);
  26.                     info(path);
  27.                 }
  28.                
  29.                 closedir(dopen);
  30.                
  31.             } else printf("ERROR DIRECTORIO 1\n");
  32.            
  33.  
  34.           } else {
  35.               dopen = opendir(pathfinal);
  36.                 if (dopen != NULL){
  37.                 while ( ((dread = readdir(dopen)) !=NULL) )
  38.                 {
  39.                    
  40.                      if((strcmp(dread->d_name, ".") == 0)
  41.                      || (strcmp(dread->d_name, "..") == 0))
  42.  
  43.                         {
  44.                             continue;
  45.                         }
  46.                          snprintf (path, PATH_MAX, "%s/%s", direccionInicial, dread->d_name);
  47.                         recursiveL(path,flag);
  48.                 }
  49.                 closedir(dopen);
  50.                
  51.             } else printf("ERROR DIRECTORIO 2\n");
  52.           }
  53.         }
  54. } else printf("ERROR DIRECTORIO 3\n");
  55. }
  56.  
  57. void recursiveN(char * direccionInicial, int flag){
  58.     char * direccion;
  59.     char path[PATH_MAX];
  60.     char pathfinal[PATH_MAX+1];
  61.     struct stat buf;
  62.     struct stat buf2;
  63.     DIR *dopen;
  64.     struct dirent *dread;
  65.        
  66.    
  67.     direccion = realpath(direccionInicial, pathfinal);
  68.  
  69.         if (direccion != NULL) {
  70.          lstat(pathfinal, &buf);
  71.          printf("%lu%s",buf.st_size, " ");
  72.          
  73.                printf("%s\n", direccionInicial);
  74.            
  75.           if (!(S_ISREG(buf.st_mode))){
  76.             if (flag != 1) {
  77.                 dopen = opendir(pathfinal);
  78.                 if (dopen != NULL){
  79.                 while ( ((dread = readdir(dopen))!=NULL) ){
  80.                  if((strcmp(dread->d_name, ".") == 0)
  81.                      || (strcmp(dread->d_name, "..") == 0)) {
  82.                          continue; //AVANZA A LA SIGUIENTE INTERACION DEL BUCLE
  83.                      } 
  84.                      snprintf (path, PATH_MAX, "%s/%s", direccionInicial, dread->d_name);
  85.                      lstat(path, &buf2);
  86.                      printf("%lu%s",buf2.st_size, " ");
  87.          if (S_ISLNK(buf.st_mode)) {
  88.                 printf("%s%s%s\n", path, " -> ",basename(path));
  89.             } else {
  90.                 printf("%s\n", path);
  91.             }
  92.                 }
  93.                
  94.                 closedir(dopen);
  95.                
  96.             } else printf("ERROR DIRECTORIO 1\n");
  97.            
  98.  
  99.           } else {
  100.               dopen = opendir(pathfinal);
  101.                 if (dopen != NULL){
  102.                 while ( ((dread = readdir(dopen)) !=NULL) )
  103.                 {
  104.                    
  105.                      if((strcmp(dread->d_name, ".") == 0)
  106.                      || (strcmp(dread->d_name, "..") == 0))
  107.  
  108.                         {
  109.                             continue;
  110.                         }
  111.                          snprintf (path, PATH_MAX, "%s/%s", direccionInicial, dread->d_name);
  112.                         recursiveN(path,flag);
  113.                 }
  114.                 closedir(dopen);
  115.                
  116.             } else printf("ERROR DIRECTORIO 2\n");
  117.           }
  118.         }
  119. } else printf("ERROR DIRECTORIO 3\n");
  120. }
  121.  
  122.  void listar(char * trozos[], int i){ //QUE SON LOS . Y .. AL HACER UN LIST Y UN INFO DE .
  123.      int flag;
  124.  
  125.      flag = recursive(trozos, i);
  126.      
  127.    
  128.         if ( (i>1) ) {
  129.            
  130.            
  131.             if ( (strcmp(trozos[1], "-l") == 0) ) {
  132.                 if(i<3) {
  133.                     recursiveL(".",flag);
  134.                 } else {   
  135.                     for(int n=2; n<i; n++){
  136.                     recursiveL(trozos[n],flag);
  137.                 }
  138.             }
  139.    }else {
  140.                 for(int n=1; n<i; n++){
  141.                    
  142.                     recursiveN(trozos[n],flag); //comprobar el caso de SYSLIM Y EL NOMBRE DEL ARCHIVO
  143.                    
  144.                     }
  145.                 }
  146.  
  147.     } else recursiveN(".",flag);
  148. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement