int main(){ int length, i = 0, fd, wd; char buffer[EVENT_BUF_LEN]; fd = inotify_init(); if (fd < 0){ perror( "inotify_init" ); } wd = inotify_add_watch(fd, pathname1, IN_MODIFY); length = read( fd, buffer, EVENT_BUF_LEN); if(length < 0){ perror("read"); } while(i < length){ struct inotify_event *event = ( struct inotify_event *)&buffer[i]; if(event->len){ if(event->mask & IN_MODIFY){ if(event->mask & IN_ISDIR){ if(event->wd == wd){ // if directory name changed. I don't know what condition to put printf("The directory name '%s' is changed with %s\n", event->name); } } else{ if(event->wd == wd){ // if file name changed. I don't know what condition to put printf("The file name '%s' is changed with %s\n", event->name); } } } } i += EVENT_SIZE + event->len; } inotify_rm_watch(fd, wd); close(fd); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)