func main() { watcher, err := inotify.NewWatcher() if err != nil { log.Fatal(err) } //err = watcher.Watch("/tmp/abc") //err = watcher.Watch("/tmp/abd") err = watcher.Watch("/tmp/abd") //err = watcher.Watch("/tmp/abd/a/v/a/w/e/e/we") if err != nil { log.Fatal(err) } for { select { case ev := <-watcher.Event: m := ev.Mask for _, b := range eventBits { if m&b.Value == b.Value { m &^= b.Value //log.Println(b.Name) switch b.Value { /* case inotify.IN_DELETE: log.Println(ev.Name, "deleted..") */ case inotify.IN_DELETE_SELF: log.Println(ev.Name, "deleted self..") case inotify.IN_MODIFY: log.Println(ev.Name, "modifed..") case inotify.IN_MOVED_FROM: log.Println(ev.Name, "moveed out..") default: fmt.Println(ev.Name, b.Name) } } } //fmt.Println(ev.String(), "][", ev.Cookie, "][", ev.Mask, "][", ev.Name) /* if ev.Mask==inotify.IN_DELETE||ev.Mask==inotify.IN_DELETE_SELF||ev.Mask==inotify.IN_MODIFY ||ev.Mask==inotify.IN_MOVED_FROM|| */ //log.Println("event:", ev) case err := <-watcher.Error: log.Println("error:", err) } } }
func main() { watcher, err := inotify.NewWatcher() if err != nil { log.Fatal(err) } err = watcher.Watch("/tmp/abc") if err != nil { log.Fatal(err) } for { select { case ev := <-watcher.Event: log.Println("event:", ev) case err := <-watcher.Error: log.Println("error:", err) } } }