1

I want to replicate all changes to a given folder. I use the FileSystemWatcher in C# and I can detect most changes. One type of change that I cannot detect easily is a move of a complete folder to the watched folder. I receive only a create-event for the folder but no events for the content of that moved folder. I can think of some logic to figure out if it is a move or just a creation of a new folder, but it seems awkward that it is quite hard to do this. Any suggestions in easy/out-of-the-box folder-move detection?

Thans a lot!

mvermand
  • 5,829
  • 7
  • 48
  • 74
  • You may want to check [this question](http://stackoverflow.com/questions/32678108/c-sharp-filesystemwatcher-copy-folder-complete) – Jcl Jan 25 '16 at 08:53
  • Possible duplicate: http://stackoverflow.com/questions/1286114/detecting-moved-files-using-filesystemwatcher – HerbalMart Jan 25 '16 at 09:25
  • @HerbalMart: that question handles more about detecting a move within the monitored folder. Solutions are to figure out the move-scenario based on the delete+create events. Though, when a move happens from outside the monitored folder, you do not get a delete-event and thus you cannot use that for move-detection... – mvermand Jan 25 '16 at 09:29

1 Answers1

1

I receive only a create-event for the folder but no events for the content of that moved folder.

That's correct as OS does not "copy+delete" the folder internals. It's just "relink" the folder in the file system. As just a 'fast' idea - you cold check if 'created' folder is empty or not at the moment the create event received. If the folder is not empty you cold assume it was moved.

MobileX
  • 409
  • 4
  • 13
  • yes that is what I am doing right now, but I thought there had to be some way to get this info from the FileSystemWatcher framework. – mvermand Jan 25 '16 at 09:11
  • Only issue is when operations are automated (copying, moving...) by applications, it is harder to tell if the files are copied just after the folder creation or if it was a move. I have a rather complex mechanism to find that out and I hoped to get the complexity out of that and use a out-of-the-box solution. I guess I will have to stick with my mechanism. – mvermand Jan 25 '16 at 09:17
  • I'm afraid you need to make a file system filter driver in order to achieve true control over file system. – MobileX Jan 25 '16 at 09:20
  • Btw, did you test how your solution works with network mapped drives? I'd suggest to do that as there can be issues potentially. – MobileX Jan 25 '16 at 09:27
  • FYI: http://stackoverflow.com/questions/11468637/filesystemwatcher-not-raising-when-files-are-copied-or-moved-to-folder – MobileX Jan 25 '16 at 11:16