Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

FileSystemMonitor - wait til file copies completely

5 views
Skip to first unread message

Bob

unread,
Jan 24, 2008, 10:54:20 AM1/24/08
to
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]

unread,
Jan 24, 2008, 11:17:59 AM1/24/08
to
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).


--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard.caspershouse.com

"Bob" <B...@no-spam.com> wrote in message
news:fichp39t9ffv59h11...@4ax.com...

Oolis Kraprin

unread,
Jan 25, 2008, 8:19:28 AM1/25/08
to
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.
0 new messages