So the code idea is as following: i pick a path in the main, go in it, if i encounter a file, just save its name and modification date in the .txt file, otherwise it should open the directory it just found, get inside and re-do the process for this directory
The rest of the process works quite fine, UNTIL i uncomment the recursive part, where it will proceed to go in itself i think (Path.), then loops to that state (go to Path.., Path... , etc), making the thing completely useless and justan infinite loop
Any ideas?
#include <dirent.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <sys/stat.h>
#include <sys/types.h>
void ecrire(char * s);
void ecrire_add(char * s);
void regarder(char * loc);
int main(void) {
char localisation[10000]="Path example";
ecrire("");
regarder(localisation);
return(0);
}
void ecrire_add(char * s){
FILE * fichiertexte;
fichiertexte = fopen(".\\liste.txt","a");
fputs(s,fichiertexte);
fclose(fichiertexte);
}
void ecrire(char * s){
FILE * fichiertexte;
fichiertexte = fopen(".\\liste.txt","w");
fprintf(fichiertexte,s);
fclose(fichiertexte);
}
void regarder(char * loc){
DIR *d;
struct dirent *dir;
char contenu[100];
char position[100];
char modification[20];
struct stat attrib;
d = opendir(loc);
strcpy(position, loc);
if (d) {
while ((dir = readdir(d)) != NULL) {
if((dir->d_name) !="$WinREAgent" && (dir->d_name) !=".." && (dir->d_name) !="." && (dir->d_name) !="\\."){
strcpy(contenu,dir->d_name);
strcat(position,"\\");
strcat(position,contenu);
stat(position,&attrib);
strftime(modification, 20, "%H:%M:%S %d-%m-%y", localtime(&(attrib.st_mtime)));
//where i think the problem starts
//this is the part i comment to check if the rest is functionnal
if((S_ISDIR(attrib.st_mode)) && (dir->d_name) !=loc){
printf("rentre doss %s \n", position);
regarder(position);
}
//where i think it ends
printf("%s \n", position);
strcat(position,"\n");
strcat(position,modification);
strcat(position,"\n \n");
ecrire_add(position);
strcpy(position,loc);
strcpy(modification,"");
}
}
}
closedir(d);
}