Archive

Archive for February 2nd, 2010

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 ,