tags:

views:

108

answers:

1

I want to call a copyFile function from within the source file to be copied. The VBA FileCopy function does not allow the source file to be open while it is copied. I am thinking of using CopyFile or CopyFileEx (to show a progress bar) instead.

Therefore, do those functions work if the source file is open?

+2  A: 

Yes, CopyFileEx() has the COPY_FILE_OPEN_SOURCE_FOR_WRITE option, allowing you to copy a file that was opened for writing. You'd still need cooperation from the owner of the file, it would have had to open the file allowing read sharing.

Beware of the trouble you can get into with this option, you'll essentially get a random snapshot of the file, you could copy the file while the app was in the middle of writing to the file. Such a copy isn't usually readable anymore. You'd be lucky if the app trying to read such a copy crashes and dies. But the more likely outcome is subtly corrupt data.

Hans Passant