Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void recursiveL(char * direccionInicial, int flag){
- char * direccion;
- char path[PATH_MAX];
- char pathfinal[PATH_MAX+1]; //HACER CONDICION SALIR EN CASO DE QUE LLEGUE AL FINAL DE LA CADENA
- struct stat buf;
- DIR *dopen;
- struct dirent *dread;
- direccion = realpath(direccionInicial, pathfinal);
- if (direccion != NULL) {
- lstat(pathfinal, &buf);
- info(direccionInicial);
- if (!(S_ISREG(buf.st_mode))){
- if (flag != 1) {
- dopen = opendir(pathfinal);
- if (dopen != NULL){
- while ( ((dread = readdir(dopen))!=NULL) ){
- if((strcmp(dread->d_name, ".") == 0)
- || (strcmp(dread->d_name, "..") == 0)) {
- continue; //AVANZA A LA SIGUIENTE INTERACION DEL BUCLE
- }
- snprintf (path, PATH_MAX, "%s/%s", direccionInicial, dread->d_name);
- info(path);
- }
- closedir(dopen);
- } else printf("ERROR DIRECTORIO 1\n");
- } else {
- dopen = opendir(pathfinal);
- if (dopen != NULL){
- while ( ((dread = readdir(dopen)) !=NULL) )
- {
- if((strcmp(dread->d_name, ".") == 0)
- || (strcmp(dread->d_name, "..") == 0))
- {
- continue;
- }
- snprintf (path, PATH_MAX, "%s/%s", direccionInicial, dread->d_name);
- recursiveL(path,flag);
- }
- closedir(dopen);
- } else printf("ERROR DIRECTORIO 2\n");
- }
- }
- } else printf("ERROR DIRECTORIO 3\n");
- }
- void recursiveN(char * direccionInicial, int flag){
- char * direccion;
- char path[PATH_MAX];
- char pathfinal[PATH_MAX+1];
- struct stat buf;
- struct stat buf2;
- DIR *dopen;
- struct dirent *dread;
- direccion = realpath(direccionInicial, pathfinal);
- if (direccion != NULL) {
- lstat(pathfinal, &buf);
- printf("%lu%s",buf.st_size, " ");
- printf("%s\n", direccionInicial);
- if (!(S_ISREG(buf.st_mode))){
- if (flag != 1) {
- dopen = opendir(pathfinal);
- if (dopen != NULL){
- while ( ((dread = readdir(dopen))!=NULL) ){
- if((strcmp(dread->d_name, ".") == 0)
- || (strcmp(dread->d_name, "..") == 0)) {
- continue; //AVANZA A LA SIGUIENTE INTERACION DEL BUCLE
- }
- snprintf (path, PATH_MAX, "%s/%s", direccionInicial, dread->d_name);
- lstat(path, &buf2);
- printf("%lu%s",buf2.st_size, " ");
- if (S_ISLNK(buf.st_mode)) {
- printf("%s%s%s\n", path, " -> ",basename(path));
- } else {
- printf("%s\n", path);
- }
- }
- closedir(dopen);
- } else printf("ERROR DIRECTORIO 1\n");
- } else {
- dopen = opendir(pathfinal);
- if (dopen != NULL){
- while ( ((dread = readdir(dopen)) !=NULL) )
- {
- if((strcmp(dread->d_name, ".") == 0)
- || (strcmp(dread->d_name, "..") == 0))
- {
- continue;
- }
- snprintf (path, PATH_MAX, "%s/%s", direccionInicial, dread->d_name);
- recursiveN(path,flag);
- }
- closedir(dopen);
- } else printf("ERROR DIRECTORIO 2\n");
- }
- }
- } else printf("ERROR DIRECTORIO 3\n");
- }
- void listar(char * trozos[], int i){ //QUE SON LOS . Y .. AL HACER UN LIST Y UN INFO DE .
- int flag;
- flag = recursive(trozos, i);
- if ( (i>1) ) {
- if ( (strcmp(trozos[1], "-l") == 0) ) {
- if(i<3) {
- recursiveL(".",flag);
- } else {
- for(int n=2; n<i; n++){
- recursiveL(trozos[n],flag);
- }
- }
- }else {
- for(int n=1; n<i; n++){
- recursiveN(trozos[n],flag); //comprobar el caso de SYSLIM Y EL NOMBRE DEL ARCHIVO
- }
- }
- } else recursiveN(".",flag);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement