Mimic File.Move if the destination already exists

前端 未结 5 1845
小鲜肉
小鲜肉 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 18:15

    I suggest you to probe first if the target file exists and if yes, delete it. Then execute a normal move operation.

    Since this sequence is not atomic, in case the destination exists you might want to rename it instead of deleting it, to avoid losing it in case the move fails.

提交回复
热议问题