You are doing the right thing with FileSystemWatcher . Windows does not have a built-in mechanism for reliable reporting.
You can connect the OS copy routine, but this does not guarantee good results: applications can freely implement their own copy by simply opening the source and target files and copying the bytes.
Renaming is different from the fact that renaming performed by the operating system cannot be easily mimicked by other means, so you can intercept all renaming with FileSystemWatcher . Note that moving between disks is more like a copy: you will not receive a renamed notification, but instead create and delete it.
So, if you really need to notice that the file is being copied, my suggested approach is this:
- Hook calls
CloseFile in addition to FileSystemWatcher . - Whenever a file is closed, it may be due to the fact that it or the source of the copy or cross-move is moved. Check its size.
- If you find two closed files with the same size in a fairly short period of time, compare the content. Quite resource-intensive, but the only reliable way to do this.
source share