-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
54 lines (52 loc) · 1.05 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
package main
import (
"github.com/fsnotify/fsnotify"
"log"
"os"
)
func main() {
if len(os.Args) <= 1 {
log.Println("请输入需要监控的文件夹路径!!")
log.Println("如: ./FileMonitor /data/local/tmp")
return
}
watch, err := fsnotify.NewWatcher()
if err != nil {
log.Fatal(err)
}
defer watch.Close()
err = watch.Add(os.Args[1])
if err != nil {
log.Fatal(err)
}
go func() {
for {
select {
case ev := <-watch.Events:
{
if ev.Op&fsnotify.Create == fsnotify.Create {
log.Println("创建: ", ev.Name)
}
if ev.Op&fsnotify.Write == fsnotify.Write {
log.Println("写入: ", ev.Name)
}
if ev.Op&fsnotify.Remove == fsnotify.Remove {
log.Println("删除: ", ev.Name)
}
if ev.Op&fsnotify.Rename == fsnotify.Rename {
log.Println("重命名: ", ev.Name)
}
if ev.Op&fsnotify.Chmod == fsnotify.Chmod {
log.Println("修改权限: ", ev.Name)
}
}
case err := <-watch.Errors:
{
log.Println("error : ", err)
return
}
}
}
}()
select {}
}