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.
Nicholas Paldino [.NET/C# MVP] - 24 Jan 2008 16:17 GMT
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).

Signature
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com
>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
[quoted text clipped - 5 lines]
> there no better way to do this? Seems like there should be a much
> simpler mechanism available by now.
Oolis Kraprin - 25 Jan 2008 13:19 GMT
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.
> 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
[quoted text clipped - 5 lines]
> there no better way to do this? Seems like there should be a much
> simpler mechanism available by now.