1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| int chercheFichier(char *fic, char *destination) {
struct dirent *entree;
struct stat s;
DIR *dir;
if( (dir = opendir(destination)) == NULL) {
printf("Impossible d'ouvrir le repertoire %s\n",destination);
return EXIT_FAILURE;
}
chdir(destination);
while( (entree = readdir(dir)) != NULL) {
if(!strcmp(entree->d_name,".") || !strcmp(entree->d_name,"..")) continue;
else {
printf("entree courante du repertoire = %s\n",entree -> d_name);
if(stat(entree -> d_name,&s)) {
printf("Impossible de recuperer les stats du fichier %s",entree->d_name);
return EXIT_FAILURE;
}
if(!(S_ISREG(s.st_mode) == 0)) {
if(!strcmp(fic,entree->d_name)) {
printf("Le fichier %s existe dans le repertoire %s\n",fic,destination);
}
}
if(!(S_ISDIR(s.st_mode) == 0)) {
printf("Repertoire rencontré = %s\n",entree -> d_name);
strcat(entree -> d_name,"/");
return chercheFichier(fic,entree -> d_name);
}
}
}
closedir(dir);
printf("Fin\n");
return 1;
} |
Partager