mastervlad Posted December 14, 2014 Report Posted December 14, 2014 (edited) Am compilat un program care imi afiseaza toate fisierele dintr-un director si ma gandeam sa-l modific astfel incat sa gasesc aceste fisiere. Vreo idee? Mersi.PS. S-a rezolvat, m-a ajutat JIHAD, multumesc. Edited December 26, 2014 by mastervlad Quote
JIHAD Posted December 16, 2014 Report Posted December 16, 2014 (edited) Cred ca ceva de genul asta vrei.Iti listeaza fisierele din directory2 care nu exista in directory1.#include <dirent.h>int main(int argc, char *argv[]){ char *temp, *temp1, *directory1, *directory2; DIR *dir1, *dir2; struct dirent *epdf; struct dirent *epdf2; if (argc == 3) { directory1 = argv[1]; directory2 = argv[2]; dir1 = opendir(directory1); dir2 = opendir(directory2); if ((dir1 != NULL) && (dir2 != NULL)){ while (epdf = readdir(dir1)){ temp = strdup(epdf->d_name); while (epdf2 = readdir(dir2)){ temp1 = strdup(epdf2->d_name); if(strcmp(temp,temp1)!=0) printf("%s/%s\n",directory2,temp1); } } closedir(dir1); closedir(dir2); } } else exit(printf("Argument missing\n")); printf("Done.\n");} Sunt mai multe moduri in care poti face asta, eu am ales calea cea mai la indemana.am updatat sa-ti accepte si argumente.iti sugerez sa reverifici codul ca l-am scris in graba... Edited December 16, 2014 by JIHAD Quote
mastervlad Posted December 16, 2014 Author Report Posted December 16, 2014 Cred ca ceva de genul asta vrei.Iti listeaza fisierele din directory2 care nu exista in directory1.#include <dirent.h>int main(int argc, char *argv[]){ char *temp, *temp1, *directory1, *directory2; DIR *dir1, *dir2; struct dirent *epdf; struct dirent *epdf2; if (argc == 3) { directory1 = argv[1]; directory2 = argv[2]; dir1 = opendir(directory1); dir2 = opendir(directory2); if ((dir1 != NULL) && (dir2 != NULL)){ while (epdf = readdir(dir1)){ temp = strdup(epdf->d_name); while (epdf2 = readdir(dir2)){ temp1 = strdup(epdf2->d_name); if(strcmp(temp,temp1)!=0) printf("%s/%s\n",directory2,temp1); } } closedir(dir1); closedir(dir2); } } else exit(printf("Argument missing\n")); printf("Done.\n");} Sunt mai multe moduri in care poti face asta, eu am ales calea cea mai la indemana.am updatat sa-ti accepte si argumente.iti sugerez sa reverifici codul ca l-am scris in graba...L-am verificat si am compilat, merge, dar cred ca trebuie sa precizez si calea fisierelor care apar in primul si nu apar in al2lea, cred ca trebuie o citire recursiva.. Quote
JIHAD Posted December 16, 2014 Report Posted December 16, 2014 (edited) te joci tu cu el mai departe. ideea e tot astauite o solutie sa-ti arate cum ai zis tu.int parsedir(char *directory1, char *directory2){ char *temp, *temp1; DIR *dir1, *dir2; struct dirent *epdf; struct dirent *epdf2; dir1 = opendir(directory1); dir2 = opendir(directory2); if ((dir1 != NULL) && (dir2 != NULL)){ while (epdf = readdir(dir1)){ temp = strdup(epdf->d_name); while (epdf2 = readdir(dir2)){ temp1 = strdup(epdf2->d_name); if(strcmp(temp,temp1)!=0) printf("%s/%s\n",directory2,temp1); } } closedir(dir1); closedir(dir2); } free(temp); free(temp1); printf("Done.\n"); return 0;} int main(int argc, char *argv[]){ if (argc == 3) { parsedir(argv[1],argv[2]); parsedir(argv[2],argv[1]); } else exit(printf("Argument missing\n")); return 0;} Edited December 16, 2014 by JIHAD Quote
JIHAD Posted December 17, 2014 Report Posted December 17, 2014 (edited) uite si recursiv.iti cauta doar intr-o directie. cauta fisiere din argv[1] (recursiv, toate subfolderele) in path2(recursiv, toate subfolderele) . le afiseaza si le si numara pe cele negasite.Sa-ti mearga in ambele directii vezi exemplul dinainte.cu placere.#include <stdio.h>#include <stdlib.h>#include <sys/types.h>#include <sys/stat.h>#include <unistd.h>#include <dirent.h>#include <sys/param.h>#include <stdbool.h>#define path2 "/etc"bool *dir2compare( char *path, char *findme ){ DIR *dir; struct dirent *entry; char spath[MAXPATHLEN] = "", spath2[MAXPATHLEN] = ""; if( !(dir = opendir( path))){ perror("opendir"); exit(1);} for( entry = readdir( dir); entry; entry = readdir( dir)){ sprintf( spath, "%s/%s", path, entry->d_name); if( entry->d_type == DT_REG){ if(strcmp(entry->d_name,findme)==0) return true; } if( entry->d_type == DT_DIR && (strcmp( ".", entry->d_name)) && (strcmp( "..", entry->d_name))){ dir2compare(spath,findme); } } closedir( dir);}char *dirfind( char *path, int *fgasit){ DIR *dir; char *temp; struct dirent *entry; char spath[MAXPATHLEN] = "", spath2[MAXPATHLEN] = ""; if( !(dir = opendir( path))){ perror("opendir"); exit(1);} for( entry = readdir( dir); entry; entry = readdir( dir)){ sprintf( spath, "%s/%s", path, entry->d_name); if( entry->d_type == DT_REG){ if(!dir2compare(path2, entry->d_name)) { printf("[*] %s\n", spath); (*fgasit)++; } } if( entry->d_type == DT_DIR && (strcmp( ".", entry->d_name)) && (strcmp( "..", entry->d_name))){ dirfind(spath, fgasit); } } closedir( dir); return(0);}int main(int argc, char *argv[]){ int i = 0; if (argc == 2){ dirfind(argv[1],&i); printf(" %d fisiere nu corespund.\n", i); }} Edited December 17, 2014 by JIHAD Quote