Skip to content
/ kwatch Public

Simple Kotlin library for listening to changes in a file or directory

License

Notifications You must be signed in to change notification settings

gimme/kwatch

Repository files navigation

kwatch

Simple Kotlin library for listening to changes in a file or directory.

Installation

Add JitPack to the list of repositories:

repositories {
    maven("https://jitpack.io")
}

Then add the dependency:

dependencies {
    implementation("com.github.gimme:kwatch:1.0.0")
}

Example Usage

Listen to file changes

val file = Path.of("file.txt")

file.onChange {
    println("file changed")
}

Watch for directory events

val dir = Path.of("dir")

dir.watch { event ->
    println("${event.path}: ${event.actions}") // Prints e.g. "dir/file.txt: [MODIFY]"
}

Cancellation

When you want to stop the listener, you simply call cancel on the returned object.

val listener = dir.watch {}

listener.cancel()

About

Simple Kotlin library for listening to changes in a file or directory

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages