views:

78

answers:

2

I'm looking for a straightforward way to watch the contents of a folder using Win32 (minimum target is XP). If possible, it would be nice to use an event-driven approach rather than a polling-type approach. To complicate things, the watched folder may be a network share.

I'm really only interested in capturing "new files". I don't care if I am not informed of renamed or removed files.

Is there an event-driven way, or is polling my only choice when dealing with Win32?

+3  A: 

Have you tried out FindFirstChangeNotification and FindNextChangeNotification . Download an example source code from here

Suraj Chandran
+2  A: 

FindFirstChangeNotification is the right API here, as Suraj says. I did however find when using this (many years ago), that it sometimes failed if used it to watch a network share with an infinite wait on the handle it returns. I simply applied a timeout and re-issued the FFCN every so often, which solved the problem.

I don't know if later OS updates solved this problem, we never went back and checked :-).

Bob Moore
Thanks for the heads up! I'll be sure to keep this in mind.
dreamlax