Detecting moved files using FileSystemWatcher

According to the docs:

Common file system operations might
raise more than one event. For
example, when a file is moved from one
directory to another, several
OnChanged and some OnCreated and
OnDeleted events might be raised.
Moving a file is a complex operation
that consists of multiple simple
operations, therefore raising multiple
events.

So if you’re trying to be very careful about detecting moves, and having the same path is not good enough, you will have to use some sort of heuristic. For example, create a “fingerprint” using file name, size, last modified time, etc for files in the source folder. When you see any event that may signal a move, check the “fingerprint” against the new file.

Leave a Comment