Skip to content
FutureBlitz

    Install

    Import std.io.watcher

    FileWatcher

    std.io.watcher

    class

    Public Class FileWatcher

    Watches a file, or what's in a folder, but not the folders in it, from when it's made until it's closed or its last reference goes. An OS can tell of one change more than once, as when a write comes in parts, and of a change it makes itself, as of a folder's times. A watched file or folder that's removed may go unwatched on some OSes, even once it's back.

    Examples

    Local watcher = Try FileWatcher(Path("assets"))
    Local event = watcher.Next()
    While event != Null
        Print("{event.Kind}: {event.Path}")
        event = watcher.Next()
    End While

    std/io/watcher.fb, line 82

    • Public ReadOnly Field Path: Path field #

      The file or folder it watches.

    • Public New(path: Path) Throws IOError constructor #

      Starts watching what's at the path, which has to be there.

    • Public Method Next(): FileEvent? method #

      The next event, waiting for it, or Null once it's closed. Nothing else runs on this thread meanwhile, so one that nothing comes to waits forever.

    • Public Method TryNext(): FileEvent? method #

      The next event if one's come, or Null.

    • Public Async Method NextAsync(): FileEvent? method #

      Next's Async twin, which waits on the main thread instead of blocking it.

    • Public Method Close() method #

      Stops watching, dropping the events not taken, so what waits for one, and each Next, gets Null. A second Close does nothing.

    Report an issue with this page or with FutureBlitz on GitHub.