Hey folks I'm stuck with a recursion problem here, I need to create a hash for each file inside some directory, the problem is when it comes to other directories inside, I need the files inside them and inside their dirs too, and so on recursively. Can someone give me a hand on this peace of code?
Code:
/*
for now my function only hashes the file in the top level root_dir
*/
int
gen_files_hashes(char *root_dir) {
DIR *dir;
char b[512];
int i=0,k;
struct dirent *ent;
dir = opendir (root_dir);
if (dir != NULL) {
while ((ent = readdir (dir)) != NULL) {
if(ent->d_type==DT_DIR)
continue; /* for now I'm just skipping dirs... */
b[0]='\0';
strncat(b, root_dir, sizeof(b)-1);
strncat(b, "/", sizeof(b)-1);
strncat(b, ent->d_name, sizeof(b)-1);
gen_file_hash(b); /* Here is where I print the file hash. */
i++;
}
closedir (dir);
} else {
/* could not open directory */
perror ("opendir()");
}
}
Thanks
[ ]'s