Stream<FileSystemEvent> watch({int events: FileSystemEvent.ALL, bool recursive: false })

Start watching the FileSystemEntity for changes.

The implementation uses platform-dependent event-based APIs for receiving file-system notifications, thus behavior depends on the platform.

  • Windows: Uses ReadDirectoryChangesW. The implementation only supports watching directories. Recursive watching is supported.
  • Linux: Uses inotify. The implementation supports watching both files and directories. Recursive watching is not supported. Note: When watching files directly, delete events might not happen as expected.
  • OS X: Uses FSEvents. The implementation supports watching both files and directories. Recursive watching is supported.

The system will start listening for events once the returned Stream is being listened to, not when the call to watch is issued.

The returned value is an endless broadcast Stream, that only stops when one of the following happends:

  • The Stream is canceled, e.g. by calling cancel on the StreamSubscription.
  • The FileSystemEntity being watches, is deleted.

Use events to specify what events to listen for. The constants in FileSystemEvent can be or'ed together to mix events. Default is FileSystemEvent.ALL.

A move event may be reported as seperate delete and create events.

Source

Stream<FileSystemEvent> watch({int events: FileSystemEvent.ALL,
                               bool recursive: false})
   => _FileSystemWatcher._watch(_trimTrailingPathSeparators(path),
                               events,
                               recursive);