Environment: Windows7 64 bit/ C#
I have folder named “Folder50”, which has 50 files inside it. When I copy this folder to the File System watch folder using ctrl + C and ctrl +V commands, sometimes system generating 51 events including the root folder.
But sometimes, system generates just one event for the root folder.
void onCreated(object source, FileSystemEventArgs e)
{
Console::WriteLine( "File: {0} {1}", e.FullPath, e.ChangeType );
}
I’ve experimented with the FileSystemWatcher quite a bit and experienced the same issues you’re having. After a bit of research I came to find out this seems to just be the way that it operates. I had some success with setting up timers to ignore additional events if they occurred within a specified time period of the last event, but obviously concurrent copies of different files would be missed as well.
More weirdness occurs if you watch all of the events available. Copying a file will trigger a delete and new file creation events, and sometimes multiples of each. Saving a file can throw a ton of writes. Overall, FileSystemWatcher is very inconsistent.
I found some help from the following website, and after a bit of modification to the code it suited my needs.
http://spin.atomicobject.com/2010/07/08/consolidate-multiple-filesystemwatcher-events/