On Saturday 30 April 2005 19:03, Laurent Renard wrote:
Hello everyone,
i'm looking for something that could listen to a directory content
( console )
and dynamicaly display it ( and display changes in real-time )
watch ls directory
perhaps?
Or if you want it to be closer to real time, a simple program that uses the
file alteration monitor would do it. Something like this (hacked together in
about 5 minutes, to give you the general idea)
#include
#include
#include
#include
#include
int main(int argc, char *argv[]){
FAMConnection fc;
FAMRequest fr;
FAMEvent fe;
DIR *dir;
struct dirent *entry;
printf("Monitoring directory %s\n", argv[1]);
if(FAMOpen(&fc)){
fprintf(stderr, "Couldn't open connection to FAM daemon\n");
exit(1);
}
if(FAMMonitorDirectory(&fc, argv[1], &fr, NULL))
exit(1);
while(FAMNextEvent(&fc, &fe) != -1){
printf("The directory changed\n");
dir = opendir(argv[1]);
while((entry = readdir(dir)) != NULL)
printf("%s\n", entry->d_name);
closedir(dir);
}
FAMClose(&fc);
return 0;
}