The most user-friendly file-system watch library written in Clojure, built on top of the Java 7 WatchEvent API.
Add this to your dependencies:
[clojure-watch "LATEST"]Check out Clojars for more specific installation instructions.
An example:
(ns clojure-watch.example
(:require [clojure-watch.core :refer [start-watch]]))
(start-watch [{:path "/home/derek/Desktop"
:event-types [:create :modify :delete]
:bootstrap (fn [path] (println "Starting to watch " path))
:callback (fn [event filename] (println event filename))
:options {:recursive true}}])You call start-watch with a collection of specifications. A specification is a map with five entries:
:path. The path to a directory that you want to watch.:event-types. A collection of the types of events that you want to watch. Possible values include:create,modify, andcreate.:bootstrap(optional). A function to be run only once whenstart-watchis invoked. The function should accept one argument: the path given in the spec.:callback. A callback function to be invoked when an event occurs. The function should accept two arguments, the first one being the type of the event that happened (:create,:modify, or:delete), and the second one being the full path to the file to which the event happened.:options. A map of options. Currently the only available option is:recursive. If it's set to true, all sub-directories will be watched.