I have the following FileSystemWatcher setup in my windows service.
FileSystemWatcher Watcher = new FileSystemWatcher();
Watcher.Path = watcherDir;
Watcher.NotifyFilter = NotifyFilters.LastWrite;
Watcher.Renamed += Watcher_Renamed;
Watcher.Changed += Watcher_Changed;
Watcher.Error += Watcher_Error;
Watcher.Filter = "*.*";
Watcher.IncludeSubdirectories = false;
Watcher.EnableRaisingEvents = true;
I see some inconsistent behavior - it listens to changes in subdirectories too. I have logged to see what it finds it is bit odd.
I am watching C:\Temp\Folder1, and some other process creates a log file in C:\Temp\Folder1\Folder2. This FileSystemWatcher object is picking this info up -
1. e.FullPath gives the name of the subdirectory, in this case C:\Temp\Folder1\Folder2
2. Path.GetDirectoryName(e.FullPath) gives me the directory that I am actually watching for i.e. C:\Temp\Folder1.
3. The extension is empty and that is how I ignore this and this is how I ignore this case.
Any suggestions for how else I can figure out what is going on here?