开发者

Watching a folder using Win32

I'm looking for a straightforward way to watch the contents of a folder using Win开发者_StackOverflow中文版32 (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?


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜