I'm trying to create a function that scans a folder on my Windows PC and every time it does, a file called "Filter.txt" is appended with the string "Test Script".
Now the problems are 2, the first is that the scan must be performed either in the directory c:\LOG or its subdirectories, and the second is that I do not know how to chain fopen
in the directory and the name of the file.
int main(){
DIR *dir;
FILE * pFile;
char myString[100];
struct dirent *ent;
dir = opendir ("c:\\LOG");
if (dir != NULL) {
/* print all the files and directories */
while ((ent = readdir (dir)) != NULL) {
pFile = fopen ("Filter.txt","a");
if (pFile==NULL)
perror("Error");
else
fprintf(pFile,"%s\n","Test scriptIno");
fclose(pFile);
//printf ("%s\n", ent->d_name);
}
closedir (dir);
} else {
/* Can not open directory */
perror ("");
return EXIT_FAILURE;
}
}