File.Move Does Not Work - File Already Exists

前端 未结 9 1221
无人及你
无人及你 2020-12-04 12:08

I\'ve got a folder:

c:\\test

I\'m trying this code:

File.Move(@\"c:\\test\\SomeFile.txt\", @\"c:\\test\\Test\");         


        
9条回答
  •  日久生厌
    2020-12-04 12:19

    If file really exists and you want to replace it use below code:

    string file = "c:\test\SomeFile.txt"
    string moveTo = "c:\test\test\SomeFile.txt"
    
    if (File.Exists(moveTo))
    {
        File.Delete(moveTo);
    }
    
    File.Move(file, moveTo);
    

提交回复
热议问题