|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
File finshed being copiedI want to copy a file from a Source location to a Destination location, but
the file is sometimes in the process of being copied to that Source location. How can I check that the file has been copied to the Source location and is ready to be copied to the Destination location, without me getting a "being used by another process" exception. Thanks, Craig AFAIK there is no good way how you can detect if file is fully copied or
still being copied. For e.g. application can open file for exclusive use, then all others will not receive access to the file. If the code that copies source file is your own, you can create mutex ( for interprocess ) or event ( for inprocess) synchronization. That is if copying is finished event is signaled, and you can start copying file to other location. Show quote "Craig HB" <Crai***@discussions.microsoft.com> wrote in message news:42E5F83C-8A3F-43CF-9B82-E1B3BAD0C8E6@microsoft.com... >I want to copy a file from a Source location to a Destination location, but > the file is sometimes in the process of being copied to that Source > location. > > How can I check that the file has been copied to the Source location and > is > ready to be copied to the Destination location, without me getting a > "being > used by another process" exception. > > Thanks, Craig I always put my file copies in a Try...Catch... handler for this very
reason. Sometimes I ignore the error and other times I wait for a few seconds and try again. Mike Ober. Show quote "Craig HB" <Crai***@discussions.microsoft.com> wrote in message news:42E5F83C-8A3F-43CF-9B82-E1B3BAD0C8E6@microsoft.com... > I want to copy a file from a Source location to a Destination location, but > the file is sometimes in the process of being copied to that Source location. > > How can I check that the file has been copied to the Source location and is > ready to be copied to the Destination location, without me getting a "being > used by another process" exception. > > Thanks, Craig As implied by Vadym and Mike - CreateFile (or any of your variants) in
exclusive mode should serve the purpose. Dinesh Sinha <http://www.geocities.com/dinesh_sinha> |
|||||||||||||||||||||||