std.fs.watch

*defaults*

dynamic

*filewatchers*

dynamic

add-io-watch

added in 3.0

(add-io-watch obj k f opts)

registers the watch to a global list of filewatchers

event-kinds

event-lookup

event-types

kind-lookup

list-io-watch

added in 3.0

(list-io-watch obj _)

list all *filewatchers

pattern

added in 3.0

(pattern s)

creates a regex pattern from the string representation

(pattern “.*”) => #“\Q.\E.+”

(pattern “*.jar”) => #“.+\Q.\Ejar”

process-event

added in 3.0

(process-event watcher kind file)

helper function to process event

register-entry

added in 3.0

(register-entry service path)

adds a path to the watch service

(-> (.newWatchService (FileSystems/getDefault)) (register-entry “src”))

register-path

added in 3.0

(register-path {:keys [service], :as watcher} path)

registers either a file or a path to the watcher (-> (watcher [] {} {}) (assoc :service (.newWatchService (FileSystems/getDefault))) (register-path “test”))

register-sub-directory

added in 3.0

(register-sub-directory watcher dir-path)

registers a directory to an existing watcher

(-> (watcher “src” {} {}) (assoc :service (.newWatchService (FileSystems/getDefault))) (register-sub-directory “test”))

remove-io-watch

added in 3.0

(remove-io-watch obj k _)

removes the watcher with the given key

run-watcher

added in 3.0

(run-watcher watcher)

initiates the watcher with the given callbacks

start-watcher

added in 3.0

(start-watcher watcher)

starts the watcher

stop-watcher

added in 3.0

(stop-watcher watcher)

stops the watcher

watch-callback

added in 3.0

(watch-callback f root k)

helper function to create watch callback

watcher

added in 3.0

(watcher paths callback options)

the watch interface provided for java.io.File

(def ^:dynamic happy (promise))

(h/watch:add (io/file “.”) :save (fn [f k _ cmd file] (h/watch:remove f k) (.delete ^File file) (deliver happy cmd (.getName ^File file))) {:types #{:create :modify} :recursive false :filter “.hara” :exclude “.git” “target”})

(h/watch:list (io/file “.”)) => (contains {:save fn?})

(spit “happy.hara” “hello”)

(deref happy) => :create “happy.hara”

(h/watch:list (io/file “.”)) => {}