+2009-05-05 Miguel de Icaza <miguel@novell.com>
+
+ * Contribution from David Uvalle <david.uvalle@gmail.com> that
+ implements FileInfo.Replace.
+
2009-04-25 Miguel de Icaza <miguel@novell.com>
* StreamReader.cs (DataAvailable): New internal function to work
public FileInfo Replace (string destinationFileName,
string destinationBackupFileName)
{
- throw new NotImplementedException ();
+ string destinationFullPath = null;
+ if (!Exists)
+ throw new FileNotFoundException ();
+ if (destinationFileName == null)
+ throw new ArgumentNullException ("destinationFileName");
+ if (destinationFileName.Length == 0)
+ throw new ArgumentException ("An empty file name is not valid.", "destinationFileName");
+
+ destinationFullPath = Path.GetFullPath (destinationFileName);
+
+ if (!File.Exists (destinationFullPath))
+ throw new FileNotFoundException ();
+
+ FileAttributes attrs = File.GetAttributes (destinationFullPath);
+
+ if ( (attrs & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
+ throw new UnauthorizedAccessException ();
+
+ if (destinationBackupFileName != null) {
+ if (destinationBackupFileName.Length == 0)
+ throw new ArgumentException ("An empty file name is not valid.", "destinationBackupFileName");
+ File.Copy (destinationFullPath, Path.GetFullPath (destinationBackupFileName), true);
+ }
+ File.Copy (FullPath, destinationFullPath,true);
+ File.Delete (FullPath);
+ return new FileInfo (destinationFullPath);
}
[ComVisible (false)]