I need to create a program that will perform a diff on all files in two different directories. Basically it's going to check for any changes between these 2 directories.
The main "base standard" directory will change as will the comparison directory.
I read the man on ftw and I believe that is the way I want to go for traversing the directory. However, I need to use the "diff" command for this processing so I need to perform an exec(X) of some sort.
Here's some sample code I tried and it works well for one file at a time:
Code:
#include <stdio.h>
main() {
FILE *fpipe;
char *command="diff /base/standard.txt /comp/standard.txt";
char line[256];
if (!(fpipe = (FILE*)popen(command, "r"))) {
perror("Problem with pipe");
exit(1);
}
while (fget(line, sizeof line, fpipe)) {
printf("%s", line);
}
pclose(fpipe);
}
My question is this. Should I use the popen for each file and store all the output from the diff command in a variable? In which case, I guess I'll have to pclose each time as well. Or should I be looking at pipe/fork/exec? At times there will be directory trees that go 5-6 levels deep and could be hundreds of files. What is the best way to make sure this scales up well?
Will sending the output of each diff command to a file incur too much time delay? This process needs to be extremely fast.
Thank you in advance for your guidance.