Skip to content

Instantly share code, notes, and snippets.

@jouyouyun
Created April 14, 2014 07:20
Show Gist options
  • Save jouyouyun/10623782 to your computer and use it in GitHub Desktop.
Save jouyouyun/10623782 to your computer and use it in GitHub Desktop.
Test fsnotify for watching dir
package main
import (
"fmt"
"github.com/howeyc/fsnotify"
"regexp"
)
func main() {
watcher, err := fsnotify.NewWatcher()
if err != nil {
fmt.Println("New Watch Failed: ", err)
return
}
if err := watcher.Watch("/tmp/Test"); err != nil {
fmt.Println("Watch dir failed: ", err)
return
}
go func() {
defer watcher.Close()
for {
select {
case ev := <-watcher.Event:
ok, _ := regexp.MatchString(".swp$", ev.Name)
if !ok {
ok, _ = regexp.MatchString(".swpx$", ev.Name)
if !ok {
fmt.Println("Watch Event: ", ev)
}
}
case err := <-watcher.Error:
fmt.Println("Watch Event Error: ", err)
}
}
}()
select {}
}
@kosl90
Copy link

kosl90 commented Apr 14, 2014

"\.swpx?$"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment