private static void CaptureEventsUsingFilter(string path) { var filter = new EventWatcher(); filter.Connect(); filter.AggregateEvents = true; filter.NotWatchProcess(EventWatcher.GetCurrentProcessId()); filter.WatchPath(path + "*"); filter.OnChange += (name, process) => { Console.WriteLine("Changed: " + name); }; filter.OnCreate += (name, process) => { Console.WriteLine("Created: " + name); }; filter.OnDelete += (name, process) => { Console.WriteLine("Deleted: " + name); }; filter.OnRenameOrMove += (name, oldName, process) => { Console.WriteLine("Moved: " + oldName + " -> " + name); }; }
protected void Initialize() { watchDir = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); Directory.CreateDirectory(watchDir); tmpFile = Path.Combine(watchDir, Path.GetRandomFileName()); File.Create(tmpFile).Dispose(); filter = new EventWatcher(); filter.Connect(); filter.WatchPath(watchDir + "*"); }