https://github.com/nir3x/filewatcher
FileWatcher - Go Package for File and Directory Watching
https://github.com/nir3x/filewatcher
file-events file-monitoring file-system filewatcher go golang
Last synced: 7 months ago
JSON representation
FileWatcher - Go Package for File and Directory Watching
- Host: GitHub
- URL: https://github.com/nir3x/filewatcher
- Owner: NIR3X
- License: agpl-3.0
- Created: 2024-01-27T03:17:06.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-02-16T04:13:01.000Z (over 1 year ago)
- Last Synced: 2024-06-21T17:03:00.539Z (over 1 year ago)
- Topics: file-events, file-monitoring, file-system, filewatcher, go, golang
- Language: Go
- Homepage:
- Size: 28.3 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# FileWatcher - Go Package for File and Directory Watching
FileWatcher is a Go package that provides a file and directory watcher with callbacks for create, remove, and modify events.
## Installation
To use FileWatcher in your Go project, you can install it using `go get`:
```bash
go get -u github.com/NIR3X/filewatcher
```## Usage
```go
package mainimport (
"fmt"
"time"
"github.com/NIR3X/filewatcher"
)func main() {
// Initialize FileWatcher
f := filewatcher.NewFileWatcher(time.Second, func(path string, isDir bool, failed func()) {
// Callback for created files and directories
if isDir {
fmt.Println("created dir:", path)
} else {
fmt.Println("created file:", path)
}
}, func(path string, isDir bool) {
// Callback for removed files and directories
if isDir {
fmt.Println("removed dir:", path)
} else {
fmt.Println("removed file:", path)
}
}, func(path string, isDir bool, failed func()) {
// Callback for modified files and directories
if isDir {
fmt.Println("modified dir:", path)
} else {
fmt.Println("modified file:", path)
}
})
defer f.Close()// Watch the current directory
err := f.Watch(".")
if err != nil {
fmt.Println("Error:", err)
return
}// Keep the application running to receive file events
select {}
}
```## API Documentation
* `NewFileWatcher`: Create a new instance of the FileWatcher.
* `Close`: Close the FileWatcher and stop watching.
* `Watch`: Start watching a specified file or directory.
* `Unwatch`: Stop watching a specified file or directory.## License
[](https://www.gnu.org/licenses/agpl-3.0.html)
This program is Free Software: You can use, study share and improve it at your
will. Specifically you can redistribute and/or modify it under the terms of the
[GNU Affero General Public License](https://www.gnu.org/licenses/agpl-3.0.html) as
published by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.