I am new to scala and have been trying to implement the directory watcher using https://index.scala-lang.org/gmethvin/directory-watcher/directory-watcher-better-files/0.13.0 library, but I am facing watching a directory recursively. I am running in Windows system.
Code
import better.files._
import io.methvin.better.files._
import scala.concurrent.ExecutionContext.Implicits.global
val myDir = File("/directory/to/watch/")
val watcher = new RecursiveFileMonitor(myDir) {
override def onCreate(file: File, count: Int) = println(s"$file got created")
override def onModify(file: File, count: Int) = println(s"$file got modified $count times")
override def onDelete(file: File, count: Int) = println(s"$file got deleted")
}
//process is not blocked here - END is printing
watcher.start()
println("END")
Problem
The process is not getting blocked at watcher.start() not sure what I am missing, as per the library spec, it is specified that for Windows use ExtendedWatchEventModifier.FILE_TREE.
How to use this ExtendedWatchEventModifier.FILE_TREE parameter??
am I missing something in the above code??
Findings
I tried to run the start() method in separate thread but no luck.
I debugged and found that start() method is internally calling DirectoryWatcher.watch() but in a different ExecutionContext, I am not able to debug that watch() method, basically the debug point is not going to DirectoryWatcher. Not sure how it works.
Please let me know what am I am missing? Please let me know if more details are required.