Detecting moved files using FileSystemWatcher

According to the docs: Common file system operations might raise more than one event. For example, when a file is moved from one directory to another, several OnChanged and some OnCreated and OnDeleted events might be raised. Moving a file is a complex operation that consists of multiple simple operations, therefore raising multiple events. So … Read more

FileSystemWatcher to watch UNC path

I just tried this: var _watcher = new FileSystemWatcher(); _watcher.Path = @”\\10.31.2.221\shared\”; _watcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName; _watcher.Filter = “*.txt”; _watcher.Created += new FileSystemEventHandler((x, y) =>Console.WriteLine(“Created”)); _watcher.Error += new ErrorEventHandler( (x, y) =>Console.WriteLine(“Error”)); _watcher.EnableRaisingEvents = true; Console.ReadKey(); That works without problems, however i replicated your exception just when: The running user doesn’t have permissions to … Read more

How to monitor a complete directory tree for changes in Linux?

I’ve done something similar using the inotifywait tool: #!/bin/bash while true; do inotifywait -e modify,create,delete -r /path/to/your/dir && \ <some command to execute when a file event is recorded> done This will setup recursive directory watches on the entire tree and allow you to execute a command when something changes. If you just want to … Read more

System.IO.FileSystemWatcher to monitor a network-server folder – Performance considerations

From a server load point of view, using the IO.FileSystemWatcher for remote change notifications in the scenario you describe is probably the most efficient method possible. It uses the FindFirstChangeNotification and ReadDirectoryChangesW Win32 API functions internally, which in turn communicate with the network redirector in an optimized way (assuming standard Windows networking: if a third-party … Read more

File access error with FileSystemWatcher when multiple files are added to a directory

A typical problem of this approach is that the file is still being copied while the event is triggered. Obviously, you will get an exception because the file is locked during copying. An exception is especially likely on large files. As a workaround you could first copy the file and then rename it and listen … Read more

Using FileSystemWatcher to monitor a directory

The problem was the notify filters. The program was trying to open a file that was still copying. I removed all of the notify filters except for LastWrite. private void watch() { FileSystemWatcher watcher = new FileSystemWatcher(); watcher.Path = path; watcher.NotifyFilter = NotifyFilters.LastWrite; watcher.Filter = “*.*”; watcher.Changed += new FileSystemEventHandler(OnChanged); watcher.EnableRaisingEvents = true; }

tech