Reputation: 154
How to determine when file copying is ended i'm using c#
edit: we copying files through network from one pc to another one. my task is to watch directory and do some actions after files are copied to it.
Upvotes: 3
Views: 6170
Reputation: 9986
Try looking into FileSystemWatcher's Created event.
Some common occurrences, such as copying or moving a file or directory, do not correspond directly to an event, but these occurrences do cause events to be raised. When you copy a file or directory,
the system raises a Created event
in the directory to which the file was copied
Upvotes: 3
Reputation: 6220
I have came across something similar recently. I would use File's open write attribute on the file to see if you can write to the file: e.g. FileStream fs = f.OpenWrite();
if the above statement works then file is not in use i.e. done copying.
Upvotes: 1
Reputation: 16032
If you are using File.Copy()
then this operation is finished after file is actually copied.
Upvotes: 6
Reputation: 6694
Periodically check for size.
Anyway, I recommend you to use CopyFileEx
, that has a progress feature (http://msdn.microsoft.com/en-us/library/aa363852(VS.85).aspx)
Upvotes: 2