Click here to Skip to main content
15,887,776 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using CopyFile to make periodic backup copies of certain files on a PC. However, these files might have been opened for writing by other applications at the time I call CopyFile and I am concerned that this may cause problems, either with the application writing to the file or with the copy operation itself.

Is there a way to copy files that are already opened (for writing)?

Thanks.

Apologies if this is posted twice, something went wrong signing in!

What I have tried:

I looked at the Volume Shadow Copy service but this appears to be for complete volume backups and not just specific files.
Posted
Updated 8-Jul-16 5:11am

1 solution

In most cases files opened for writing will be opened with exclusive access so that trying to open them for reading will fail. If you want to copy such files using the Volume Shadow Service is - as far as I know - the only solution.

You might have a look at GitHub - candera/hobocopy: An open source backup tool for Windows[^] and GitHub - candera/shadowspawn: A Windows utility that mounts a shadow copy of the disk at a drive letter and then spawns an arbitrary command.[^]. Both support copying of single files. They are no no longer under active development but the sources may be helpful to implement copying files using the Volume Shadow Service.
 
Share this answer
 
Comments
softwaremonkey 11-Jul-16 15:48pm    
Thanks. I checked out the code you suggested and it was extremely useful. My backup program is now working with VSS.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900