Reputation: 12716
I'm using the FileSystemWatcher
to monitor a certain directory, and I need to raise one event when someone saves edits to a file, and another when they create or move a file.
Monitoring moved files works fine using a combination of the Deleted
and Created events. And when someone saves edits to a file the Changed event does indeed get raised. However, when they move a file the Changed
event gets raised too, and that interferes with the handling I've got for the Created
and Deleted events.
So basically, I want to raise the Changed
event only when the user saves edits to a file, while not when the user moves or creates a file. I tried using the ChangeType
property to check if it was in fact a Changed
event or a Created
event, but to my surprise, the ChangeType
Changed
was raised for the Change event even when moving or creating a file, not the ChangeType
Created
(which supposedly should be one of the types).
So I don't know how to check that the Change event is actually triggered by a file edit, rather than file creation or move...
Any ideas?
Upvotes: 3
Views: 3107
Reputation: 16162
This is normal behavior when you apply some of NotificationFilter
such as NotifyFilter. Attributes
and NotifyFilter.LastAccess
, it will even notify Changed
twice if both filters was applied when file move "Deleted - Created - Changed - Changed", So:
NotifyFilter. Attributes
and NotifyFilter.LastAccess
you will not receive Changed
event when move file, only Deleted
then Created
.Deleted
, Created
then Changed
, they will be always in this order..Upvotes: 5