QUOTE(danZ @ Feb 12 2004, 02:52 PM)
There is an easy way to implement this using the Win32 API instead of using something like the pseudo-code posted a few replies back.
FindFirstChangeNotification
FindNextChangeNotification
FindCloseChangeNotification
is the API that makes this pretty simple to implement and it is efficient since it is event driven vs. polling the directory contents.
True, except that using the change notifications thing will only tell you files that have changed since you started watching the folder in question. That is, you Start the first change notification, then get back what changes in there.. If something changed while your program was shut down, then you never notice it this way.
Oh, and if you run this for long periods of time, like in a service, it stops working for no reason after a while. You simply stop getting that event back. Never have figured out why it stops telling you when things change, it just happens. On NT systems it seemed to stop more often, but after a month or two of running, it stops working on 2K/XP systems as well. Polling on a timer and sleeps may be ugllier, but it's more reliable in the long term. It's also easier to port to other platforms (not that that matters in this case).
Anyway, I'm offtopic now.