forked from rjeczalik/notify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_readdcw_test.go
40 lines (33 loc) · 1.2 KB
/
example_readdcw_test.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
// Copyright (c) 2014-2015 The Notify Authors. All rights reserved.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
// +build windows
package notify_test
import (
"log"
"github.com/rjeczalik/notify"
)
// This example shows how to watch directory-name changes in the working directory subtree.
func ExampleWatch_windows() {
// Make the channel buffered to ensure no event is dropped. Notify will drop
// an event if the receiver is not able to keep up the sending pace.
c := make(chan notify.EventInfo, 4)
// Since notify package behaves exactly like ReadDirectoryChangesW function,
// we must register notify.FileNotifyChangeDirName filter and wait for one
// of FileAction* events.
if err := notify.Watch("./...", c, notify.FileNotifyChangeDirName); err != nil {
log.Fatal(err)
}
defer notify.Stop(c)
// Wait for actions.
for ei := range c {
switch ei.Event() {
case notify.FileActionAdded, notify.FileActionRenamedNewName:
log.Println("Created:", ei.Path())
case notify.FileActionRemoved, notify.FileActionRenamedOldName:
log.Println("Removed:", ei.Path())
case notify.FileActionModified:
panic("notify: unexpected action")
}
}
}