I have two files: A and B. I need to replace B with A, and B in another program.
The following approach:
MoveFile to rename B to C, then rename A to B and then delete C
works great. However, I need an atomic way to do this, because if one renaming fails, the data will be left in an inconsistent state.
I tried MoveFileEx with the MOVEFILE_REPLACE_EXISTING flag, but it does not work when file B is opened by another program. Same thing for the ReplaceFile function. Any other ideas? thank you
source share