-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
52 lines (45 loc) · 1.17 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
package main
import (
"log"
"os"
"path/filepath"
"github.com/fsnotify/fsnotify"
)
func main() {
watcher, err := fsnotify.NewWatcher()
if err != nil {
log.Fatal(err)
return
}
defer watcher.Close()
path := "C:/Users/ikiru.yoshizaki/go/src/github.com/guitarrapc/go-lab/ioLab/filesystem_watcher/fsnotify/logs"
err = watcher.Add(path)
if err != nil {
log.Fatalf("Watcher.Watch() failed: %s", err)
}
go func() {
for err := range watcher.Errors {
log.Fatalf("error received: %s", err)
}
}()
go func() {
for {
select {
case e := <-watcher.Events:
if e.Op&fsnotify.Create == fsnotify.Create {
log.Printf("create event detected. %s, %s", e.Name, e.String())
} else if e.Op&fsnotify.Rename == fsnotify.Rename {
log.Printf("rename event detected. %s, %s", e.Name, e.String())
} else if e.Op&fsnotify.Remove == fsnotify.Remove {
log.Printf("remove event detected. %s, %s", e.Name, e.String())
} else if e.Op&fsnotify.Write == fsnotify.Write {
log.Printf("write event detected. %s, %s", e.Name, e.String())
}
}
}
}()
f, err := os.Create(filepath.Join(path, "hogemoge.log"))
f.Close()
end := make(chan string, 1)
<-end
}