tags:

views:

50

answers:

2

Hi,

the Windows API SHChangeNotifyRegister can detect file creation in disk, but how to know if 'file creation' is caused by file copy or not? thank you!

[EDITED], I mean SHChangeNotifyRegister, but not SHChangeNotify, sorry!

A: 

SHChangeNotify is not an API which tells you that something has changed, but an API which you tell the shell that you changed something and it should update its views accordingly.

Maybe what you want is ReadDirectoryChangesW

Stefan
Hi Stefan, sorry for the confusion! I meant to write SHChangeNotifyRegister :P
Edwin
+1  A: 

If you know the file name which is changed you can examine it's creation and last write times with respect of GetFileTime. If you copy a file from one directory to another you don't modify the file contain, so the last write times will stay unchanged.

Oleg
Thanks Oleg, but I seem can't get the source file name in the notification events fired by API SHChangeNotifyRegister...
Edwin
@Edwin: You can download "Common Notify Watcher Sample" example from the http://code.msdn.microsoft.com/shellapplication. It shows how to see the path of the modilied file. In case of copy of the new file in the watching directory you will receive the `SHCNE_CREATE` message with the name of the new file. You need to have only the **destination** file name (the name on new file). You get its create time and the last write time. It file was copied, the create time will be **newer** (the time of file coping) as the last write time which stay unchanged.
Oleg
Hi Oleg, thank you so much, even I've not tried it but I think it makes sense!
Edwin