gmethvin / directory-watcher

A cross-platform Java recursive directory watcher, with a JNA macOS watcher and Scala better-files integration
Apache License 2.0
264 stars 34 forks source link

Allow watching directory non-recursively #54

Open dneuschaefer-rube opened 3 years ago

dneuschaefer-rube commented 3 years ago

I think it would be a nice addition to allow watching a directory non-recursively.

Currently, when registering a Path with the builder, the watcher is either set up with the FILE_TREE modifier or recursively for all descendant directories, depending on system capabilities. I circumvent this by instantiating the watcher with an empty path list, then initializing paths and pathHashes with a single path and hashes for all files, and then calling register(path, false), all using reflection. This does what I want, but needless to say, that's not great practice ;)

Thanks for the great library!

gmethvin commented 3 years ago

I think it would certainly be possible. The logic would be relatively simple except that I'm not quite sure how to configure non-recursive watching for macOS, so maybe we'll just have to filter events that are in a subdirectory.

I'm definitely open to adding the feature. Are you interested in attempting a fix?