Code:
FileSystemWatcher fileSystemWatcher = new FileSystemWatcher(path, "*.exe");
fileSystemWatcher.IncludeSubdirectories = true;
fileSystemWatcher.Created += new FileSystemEventHandler(fileSystemWatcher_Created);
fileSystemWatcher.Deleted += new FileSystemEventHandler(fileSystemWatcher_Deleted);
fileSystemWatcher.EnableRaisingEvents = true;
The Created Event works fine, but the Deleted Event is only firing, when Deleting a Directory/or Exe with SHIFT. But normal-delete (moving to recycle bin) isn’t working/firing the event!
How to solve the problem?
This is expected behaviour as the file isn’t actually deleted: it’s moved.
Try attaching to
and checking if the file is moved to the Recycle Bin instead.
Finding where the recycle bin actually is in the filesystem is not trivial, mind you. Some code posted by others (untried) is here: http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/5d2be9aa-411c-4fd1-80f5-895f64aa672a/ – and also here: How can I tell that a directory is the recycle bin in C#?