6 Filesystem
6.1 Detecting changes to files
Its sometimes useful to get notified when certain files change so you can perform an action. As an example, I wanted to automatically rebuild the Scribble documentation for Rain whenever I changed the docs. To do this, you can use the watch procedure.
procedure
(watch path func) → void
path : string? func : proc?
Runs func whenever path is created/modified/deleted
path can either be a directory or a file. If path is a directory then func will run whenever any file directly below path is created/deleted/modified
watch returns immediately. func runs in its own thread.
Note: it wont recurse to sub-directories.
Example:
(watch "/home/pat/projects/rain/docs" (lambda (x) {scribble --htmls --dest docs docs/rain.scrbl}))
To stop watching use the stop-watching proc:
procedure
(stop-watching path) → void
path : string?
Removes the watch thread for path.
To stop the watch for the above example:
(stop-watching "/home/pat/projects/rain/docs")