Skip to content

Latest commit

 

History

History
49 lines (36 loc) · 819 Bytes

File metadata and controls

49 lines (36 loc) · 819 Bytes

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()