TechieGuy12 / FileWatcher

A file and folder monitor that can send notifications, perform actions, or execute a command when a file or folder is changed.
MIT License
106 stars 27 forks source link

CHANGE EVENT SETUP, WHY CREATE EVENT ALSO WOULD BE TREATED AS CHANGED EVENT #44

Closed ericxin1982 closed 1 month ago

ericxin1982 commented 1 month ago

Hi @TechieGuy12

I set up watcher to listen to file change, but when I created a newly added file there, this event also would be triggered, why? I understand it should not be triggered since it is created.

Thanks Eric Xin

TechieGuy12 commented 1 month ago

Whle I don't know the context of how the file is created, but this is from Microsoft's documentation on the created event:

The OnCreated event is raised as soon as a file is created. If a file is being copied or transferred into a watched directory, the OnCreated event will be raised immediately, followed by one or more OnChanged events.

Basically, a create event could trigger one or more changed events as the files could be changed after they are created. Changes include things such as file permissions that are applied after it is created.

ericxin1982 commented 1 month ago

OK, I see, that makes sense, so can we stop propagating from create to change, the context is a generation scheduler to generate a file to a watched directory, but I ignore create event, but only change event can check the file content, something like that. But the audit history told me when the file created, the log is recorded, I was puzzled but I am clear now, if there is no propagation then I still have idea how to bypass it. Thanks for your big help and passion given.