FileSystemWatcher Question

  • Thread starter Thread starter Al Reid
  • Start date Start date
A

Al Reid

I have been asked to write a program to monitor a certain directory
structure and to copy all files created there to optical media for archival
storage. It seems that it would be simple to monitor the directory for
file creation and just copy the files. I am concerned that while doing the
copy a "Created" event may get lost and the file not get archived. How
would I handle this?

Would it be feasible to put the paths of the newly created files into a FIFO
queue and to have a separate thread monitor the FIFO and do the copying?
Would that work? If so, how would I go about creating and running the
separate thread. I've never dealt with threads before. Also, would it be
better to have more that one thread, or is that asking for trouble?

TIA,
 
Well, in the absence of any input telling me not to do it, I went ahead an coded up a prototype. It monitors a directory structure
for creation and change events and places the events into a shared queue. A worker thread monitors the queue and performs the copy
operations into a "mirror" location. It seems to be working well and I don't seem to be loosing any events, even when monitoring a
network share.

The only puzzling thing is that I get multiple events for the same file at times. It looks like I get 1, 2 or 3 events in sequence.
Perhaps I'm getting separate change events for file size, last write time, etc. Does anyone have any suggestions as to how to
handle this. Worst case, it just copies/overwrites the file multiple times to the same location.

Thanks for your input and insight.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top