-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
55 lines (48 loc) · 1.08 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"log"
"gopkg.in/fsnotify/fsnotify.v1"
)
func main() {
counter := 0
watcher, err := fsnotify.NewWatcher()
if err != nil {
panic(err)
}
defer watcher.Close()
done := make(chan bool)
go func() {
for {
select {
case event := <-watcher.Events:
log.Println("event:", event)
if event.Op&fsnotify.Create == fsnotify.Create {
log.Println("created file:", event.Name)
counter++
} else if event.Op&fsnotify.Write == fsnotify.Write {
log.Println("modified file:", event.Name)
counter++
} else if event.Op&fsnotify.Remove == fsnotify.Remove {
log.Println("removed file:", event.Name)
counter++
} else if event.Op&fsnotify.Rename == fsnotify.Rename {
log.Println("renamed file:", event.Name)
counter++
} else if event.Op&fsnotify.Chmod == fsnotify.Chmod {
log.Println("chmod file:", event.Name)
counter++
}
case err := <-watcher.Errors:
log.Println("error:", err)
}
if counter > 3 {
done <- true
}
}
}()
err = watcher.Add(".")
if err != nil {
log.Fatal(err)
}
<-done
}