Created
May 20, 2016 22:31
-
-
Save ffrank/b7069bbc75e07a0dd32d85e9044c2ca2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"gopkg.in/fsnotify.v1" | |
"os" | |
) | |
var watcher *fsnotify.Watcher | |
func doWatch(path string) { | |
fmt.Printf("watching %v\n", path) | |
watcher.Add(path) | |
} | |
func unWatch(path string) { | |
fmt.Printf("unwatching %v\n", path) | |
watcher.Remove(path) | |
} | |
func main() { | |
watcher, _ = fsnotify.NewWatcher() | |
os.Mkdir("/tmp/watch-test", 0777) | |
os.Mkdir("/tmp/watch-test/a", 0777) | |
os.Mkdir("/tmp/watch-test/a", 0777) | |
doWatch("/tmp/watch-test") | |
doWatch("/tmp/watch-test/a") | |
doWatch("/tmp/watch-test/b") | |
unWatch("/tmp/watch-test") | |
doWatch("/tmp/watch-test") | |
fmt.Println("removing /tmp/watch-test/a") | |
os.Remove("/tmp/watch-test/a") | |
unWatch("/tmp/watch-test") | |
doWatch("/tmp/watch-test") | |
fmt.Println("done") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment