Creates an instance using the Win32 API
Creates an instance using the linux inotify API
Generic fallback implementation using std.file.dirEntries
Implementation using Win32 API or polling for files
Generic polling implementation
Implementation using inotify
Path of the file set using the constructor
import core.thread; FileChangeEvent waitForEvent(ref FileWatch watcher) { FileChangeEvent[] ret; while ((ret = watcher.getEvents()).length == 0) { Thread.sleep(1.msecs); } return ret[0]; } if (exists("test")) rmdirRecurse("test"); scope (exit) { if (exists("test")) rmdirRecurse("test"); } auto watcher = FileWatch("test", true); mkdir("test"); auto ev = waitForEvent(watcher); assert(ev.type == FileChangeEventType.createSelf); write("test/a.txt", "abc"); ev = waitForEvent(watcher); assert(ev.type == FileChangeEventType.create); assert(ev.path == "a.txt"); Thread.sleep(2000.msecs); // for polling variant append("test/a.txt", "def"); ev = waitForEvent(watcher); assert(ev.type == FileChangeEventType.modify); assert(ev.path == "a.txt"); rename("test/a.txt", "test/b.txt"); ev = waitForEvent(watcher); assert(ev.type == FileChangeEventType.rename); assert(ev.path == "a.txt"); assert(ev.newPath == "b.txt"); remove("test/b.txt"); ev = waitForEvent(watcher); assert(ev.type == FileChangeEventType.remove); assert(ev.path == "b.txt"); rmdirRecurse("test"); ev = waitForEvent(watcher); assert(ev.type == FileChangeEventType.removeSelf);
An instance of a FileWatcher Contains different implementations (win32 api, inotify and polling using the std.file methods) Specify version = FSWForcePoll; to force using std.file (is slower and more resource intensive than the other implementations)