// Moves a given file to a new location and potentially a new file name.
// This method does work across volumes.
public void MoveTo(string destFileName)
{
if (destFileName == null)
{
throw new ArgumentNullException(nameof(destFileName));
}
if (destFileName.Length == 0)
{
throw new ArgumentException(SR.Argument_EmptyFileName, nameof(destFileName));
}
string fullDestFileName = Path.GetFullPath(destFileName);
// These checks are in place to ensure Unix error throwing happens the same way
// as it does on Windows.These checks can be removed if a solution to #2460 is
// found that doesn't require validity checks before making an API call.
if (!new DirectoryInfo(Path.GetDirectoryName(FullName)).Exists)
{
throw new DirectoryNotFoundException(SR.Format(SR.IO_PathNotFound_Path, FullName));
}
if (!Exists)
{
throw new FileNotFoundException(SR.Format(SR.IO_FileNotFound_FileName, FullName), FullName);
}
FileSystem.MoveFile(FullPath, fullDestFileName);
FullPath = fullDestFileName;
OriginalPath = destFileName;
_name = Path.GetFileName(fullDestFileName);
// Flush any cached information about the file.
Invalidate();
}