Question

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?

Was it helpful?

Solution

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

OTHER TIPS

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 :-).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top