Inclusion/Exclusion filters

{
  InclusionFilter: []string
  ExclusionFilter: []string
}

These two properties instruct the FsWatcher to include or exclude specific file-masks.

By default, InclusionFilter is [‘*’], so it includes everything, while ExclusionFilter is empty, so nothing will be excluded.

Example:

{
  ConsoleFeedback = true;
  // Create the file-system watcher
  watcher = new FsWatcher();
  // Set file-system watcher properties
  watcher.DelayBySeconds = 300;
  watcher.NotifyRename = false;
  watcher.NotifyRemove = false;
  watcher.NotifyChmod = false;
  watcher.InclusionFilter = ['*.*']; // include everything
  watcher.ExclusionFilter = ['notes.txt']; // exclude 1 file by name
  watcher.WatchDir('C:\\TestFolder', false);
  // Start the file-system watcher
  watcher.Start();
  while (true) {
    Sleep(500);
    if (HaltSignalReceived()) {
      break;
    }
    // Acquire the list of pending event that we need to process
    evt = watcher.Events()
    // Do we have at least 1 event to process?
    if (evt.length > 0) {
      // We only connect to the server IF there are events to be processes
      var scli = new SftpClient();
      scli.Host = 'your.sftpserver.com:22';
      scli.User = 'your_username';
      scli.Pass = 'your_password';
      scli.Options.UploadPolicy = AlwaysOverwrite;
      if (scli.Connect()) {
        // Cycle over all pending events...
        for (var i = 0; i < evt.length; i++) {
          if (evt[i].Event == 'WRITE') {
            // If it is a WRITE event (new or modified file) let's upload it to the server
            scli.UploadWithPath(evt[i].Object, '/destinationpath', 1);
          }
        }
        // Do not forget to close the connection
        scli.Close();
      }
      scli = null;
    }
  }
}