MoveFile() public abstract method

public abstract MoveFile ( string sourceFullPath, string destFullPath ) : void
sourceFullPath string
destFullPath string
return void
Beispiel #1
0
        // 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();
        }
Beispiel #2
0
        public static void Move(string sourceFileName, string destFileName, bool overwrite)
        {
            ArgumentException.ThrowIfNullOrEmpty(sourceFileName);
            ArgumentException.ThrowIfNullOrEmpty(destFileName);

            string fullSourceFileName = Path.GetFullPath(sourceFileName);
            string fullDestFileName   = Path.GetFullPath(destFileName);

            if (!FileSystem.FileExists(fullSourceFileName))
            {
                throw new FileNotFoundException(SR.Format(SR.IO_FileNotFound_FileName, fullSourceFileName), fullSourceFileName);
            }

            FileSystem.MoveFile(fullSourceFileName, fullDestFileName, overwrite);
        }