fsnotify — screenshot of github.com

fsnotify

fsnotify is a solid Go library for cross-platform filesystem event monitoring. It's my go-to for tracking file changes, which can then trigger other actions, like desktop notifications.

Visit github.com →

Questions & Answers

What is fsnotify?
fsnotify is a Go library that provides cross-platform filesystem notifications. It allows Go applications to monitor directories and files for events such as creations, writes, renames, deletions, and permission changes across Windows, Linux, macOS, BSD, and illumos.
Who should use the fsnotify Go library?
Developers building Go applications that need to react to real-time changes in the filesystem should use fsnotify. This includes tools for file synchronization, content management systems, or any service requiring immediate awareness of file modifications.
How does fsnotify achieve cross-platform filesystem monitoring?
fsnotify leverages native operating system APIs for filesystem event monitoring, such as inotify on Linux, kqueue on BSD/macOS, and ReadDirectoryChangesW on Windows. This approach ensures efficient and reliable event detection tailored to each platform's capabilities.
When should I use fsnotify in my Go project?
Use fsnotify when your Go application needs to automatically detect and respond to filesystem events without continuously polling. It is ideal for scenarios where immediate action is required upon file creation, modification, or deletion, such as triggering builds or data processing.
Can fsnotify watch individual files or entire directories?
While fsnotify can watch individual files, it is generally recommended to watch the parent directory instead. Many programs update files atomically by writing to temporary files and then moving them, which can cause the original file's watcher to be lost. Watching directories provides more robust event capture.