int main() { DIR *flow_directory; struct dirent *flow_files; struct stat *dir_ent_stat = malloc(sizeof(struct stat)); char fentry[512]; int numfile, i, file_count = 0; char *file_list[10000]; char *file_regex = regcmp(FILE_REGEX); if(!(flow_directory = opendir(FLOWDIR))) { perror("Couldnt open flow directory: "); exit(-1); } while(1) { /* Enter never ending loop */ printf("Polling for files matching regex %s\n", FILE_REGEX); while(flow_files = readdir(flow_directory)) { snprintf((char *)&fentry, 512, "%s/%s",FLOWDIR, flow_files->d_name); if(!(stat((char *)&fentry, dir_ent_stat))) { if(S_ISREG(dir_ent_stat->st_mode)) { file_list[numfile] = strdup((char *)&fentry); numfile++; } } } for(i = 0; i < numfile; i++) if(regex(file_regex, file_list[i])) file_count++; printf("Found %d matching files on last poll\nSleeping for 30 seconds before polling...\n", file_count); file_count = 0; sleep(30); } }