I have a pet project I'm working on where the FileSystemWatcher is vexing me.
Here's the initialization code:
for (var xx = 0; xx < _roots.Count; xx++)
{
var watcher = new FileSystemWatcher();
var root = _roots[xx];
watcher.Path = root;
// watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName;
watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName;
watcher.Filter = "*.*";
watcher.Changed += new FileSystemEventHandler(OnChanged);
watcher.Created += new FileSystemEventHandler(OnChanged);
watcher.Deleted += new FileSystemEventHandler(OnChanged);
watcher.Renamed += new RenamedEventHandler(OnRenamed);
watcher.EnableRaisingEvents = true;
_rootWatchers.Add(watcher);
}
Let's say the root we're watching "c:\root" and there's a sub directory "c:\root\subdir" that contains a file called "file1.txt".
The watcher is up and running and I delete "file1.txt". When the handler is called and examine the values of FileSystemEventArgs
.
I expect for e.Name == "file1.txt"
and e.FullPath == "c:\\root\\subdir\\file1.txt
.
The actual values are "subdir"
and "c:\\root\\subdir"
.
I'm sure it's something simple I missed in the documentation somewhere.