Mimic File.Move if the destination already exists

前端 未结 5 1828
小鲜肉
小鲜肉 2020-12-20 17:48

From the documentation of File.Move:

Note that if you attempt to replace a file by moving a file of the same name into that directory, you get an IOEx

5条回答
  •  时光取名叫无心
    2020-12-20 17:56

    This is safe. File.Copy will either succeed entirely or throw. Of course, the delete could fail leaving the source file behind as garbage.

    If your computer crashes, though, there is no guarantee that the copy oepration has hardened the data yet. You might loose data in that case.

    During normal operations this is safe.

提交回复
热议问题