Home > Techie > FileInfo to overwrite when moving files

FileInfo to overwrite when moving files

February 2nd, 2010

The FileInfo.MoveTo method does not accept a parameter to overwrite destination files.

Short of extending this class (which I probably should do if I wasn’t being so lazy), the quickest way to get around this is to use the CopyTo method, set the overwrite parameter to true, and then delete the original file.


// Move an overwrite any destination file
FileInfo f = new FileInfo("SomeFile.txt");
f.CopyTo("SomeDestinationFile.txt", true);
f.Delete();

Techie ,

  1. Bappa Malakar
    February 25th, 2010 at 10:36 | #1

    Thanks Dear !
    You just saved me.

  1. No trackbacks yet.