FileSystemMonitor - wait til file copies completely

  • Thread starter Thread starter Bob
  • Start date Start date
B

Bob

I need to monitor a file system to tell when a certain file (type) has
been copied to a folder. It would seem logical to have some
pre-packaged mechanism to detect completion of the copy, but it
apparently does not exist. (The detector triggers as soon as the file
-starts- to copy, not when it's complete)

I've seen people mention hooking a call to file open into a timer. Is
there no better way to do this? Seems like there should be a much
simpler mechanism available by now.
 
Bob,

The only way I have gotten around this is to have whatever process
writing the file write a "marker" file. A zero byte file to indicate that
the file writing is complete. Then, when the FileSystemWatcher detects this
file, it determines (from the filename is the system I used) the name of the
file to process, and when it is done, deletes the marker file, or both.

If you can't change the process that is outputting the file, then a
timer is really the only way you can do this. Either that, or if you know
that the process writing the file will have exclusive access to the file,
cycle in a loop (waiting in between so you don't spin the processor
needlessly) until you can get access to the file, or you time out (as
specified by you).
 
Try handling the Watchers Changed rather than Created event. Usually
Created is fired when the write starts, and Changed is fired again
when the write is complete and the file is closed by the writer.
 

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