Fsnotify on macos

I am trying to create a directory watcher using fsnotify on macos. On my tests, I’ve noticed that when I remove a file, i am receiving a rename event notification, not a remove. Would you guys know if I am missing something?

The following code is based on example_test.go

package main

import (


func main() {

func ExampleNewWatcher() {
	watcher, err := fsnotify.NewWatcher()
	if err != nil {
	defer watcher.Close()

	done := make(chan bool)
	go func() {
		for {
			select {
			case event := <-watcher.Events:
				log.Println("event:", event)
			case err := <-watcher.Errors:
				log.Println("error:", err)

	err = watcher.Add("/Users/blabla/go/src/sync")
	if err != nil {

Thank you for your help! :slight_smile:

What does your test do? (Removing a file in Finder just renames into the trash can…)

What does your test do?
It should call a callback when the remove event is called.

That’s the expected result of your test, not what the test does - i.e, the procedure.

If removing file in Finder is just a renaming action, is there a way to know when a file is really removed or renamed?

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.