This module allows you to monitor files or directories for changes using asyncio.
Warning: This module will likely disappear soon and be moved into a new Nimble package.
Windows support is not yet implemented.
Note: This module uses inotify on Linux (Other Unixes are not yet supported). inotify was merged into the 2.6.13 Linux kernel, this module will therefore not work with any Linux kernel prior to that, unless it has been patched to support inotify.
Types
FSMonitor = ref FSMonitorObj
- Source Edit
MonitorEventType = enum MonitorAccess, ## File was accessed. MonitorAttrib, ## Metadata changed. MonitorCloseWrite, ## Writable file was closed. MonitorCloseNoWrite, ## Non-writable file closed. MonitorCreate, ## Subfile was created. MonitorDelete, ## Subfile was deleted. MonitorDeleteSelf, ## Watched file/directory was itself deleted. MonitorModify, ## File was modified. MonitorMoveSelf, ## Self was moved. MonitorMoved, ## File was moved. MonitorOpen, ## File was opened. MonitorAll ## Filter for all event types.
- Monitor event type Source Edit
MonitorEvent = object case kind*: MonitorEventType of MonitorMoveSelf, MonitorMoved: oldPath*: string ## Old absolute location newPath*: string ## New absolute location else: fullname*: string ## Absolute filename of the file/directory affected. name*: string ## Non absolute filepath of the file/directory ## affected relative to the directory watched. ## "" if this event refers to the file/directory ## watched. wd*: cint ## Watch descriptor.
- Type of the event. Source Edit
Procs
proc newMonitor(): FSMonitor {.
raises: [OSError], tags: [].}- Creates a new file system monitor. Source Edit
proc add(monitor: FSMonitor; target: string; filters = {MonitorAll}): cint {.
discardable, raises: [OSError], tags: [].}- Adds target which may be a directory or a file to the list of watched paths of monitor. You can specify the events to report using the filters parameter. Source Edit
proc del(monitor: FSMonitor; wd: cint) {.
raises: [OSError], tags: [].}-
Removes watched directory or file as specified by wd from monitor.
If wd is not a part of monitor an EOS error is raised.
Source Edit proc register(d: Dispatcher; monitor: FSMonitor; handleEvent: proc (m: FSMonitor; ev: MonitorEvent) {.
closure.}) {.raises: [], tags: [].}- Registers monitor with dispatcher d. Source Edit