Search the Community
Showing results for tags 'dir'.
-
Am urmatoarea problema in c care imi spune care fisiere sunt in dir1 si NU sunt in dir2. Problema e urmatoarea:sa spunem ca dir1 are ca subdirector pe a si in a avem fisierul bbb, iar in dir2 am doar fisierul bbb. Mie o sa-mi spuna programul ca fisierul bbb se afla si in dir1 si in dir2, dar defapt nu se afla oarecum pe acelasi nivel, si in dir1 se afla in subdirectorul a. Eu vreau sa-mi spuna ca acest bbb din dir1 e diferit de cel din dir2, cum pot as putea sa modific ca sa mearga? Mersi. #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 <limits.h> #include <string.h> char *path2; int dir2compare( char *path, char *findme ){ DIR *dir; struct dirent *entry; char spath[PATH_MAX] = "", spath2[PATH_MAX] = ""; 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 1; } 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[PATH_MAX] = "", spath2[PATH_MAX] = ""; 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)==0) { 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 == 3){ path2=strdup(argv[2]); dirfind(argv[1],&i); printf(" %d fisiere nu corespund.\n", i); } }