in reply to Monitoring directory for new files
If a file isn't finished being created, your read loop will hang while waiting for EOF. That appears to be fine in your app.
The potential race condition comes into play after you have finished processing all files that you knew about when you got the triggering event.
It could be that a new file has been or is being created in the "drop directory" since you last checked. So you run the "process_all_files()" routine again to make sure that the directory is empty as far as you know.
But this is may still not be perfect. Unless you have good OS event support and I'm not sure that Windows does, you should run process_all_files() when the event trigger happens, then run process_all_files() again to clear the directory "to the best of your knowledge". And then run process_all_files() periodically so that no "files get stuck" in the drop directory without an event trigger.
There are various alternate schemes, but the above is a good one provided that you can deal with a little delay when a file "gets stuck", which won't happen often.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Monitoring directory for new files
by ikegami (Patriarch) on Jan 20, 2010 at 06:01 UTC | |
by Marshall (Canon) on Jan 20, 2010 at 06:12 UTC | |
by ikegami (Patriarch) on Jan 20, 2010 at 15:53 UTC |