///<summary> /// Renames a file to a destination ///</summary> ///<param name="newName">the new name of the file</param> public File To(string newName) { var newPath = Path.GetDirectoryName(_file.ToString()) + "\\" + newName; FailableActionExecutor.DoAction(OnError, _fileSystemWrapper.MoveFile, _file.ToString(), newPath); _file.Path = newPath; return(_file); }
///<summary> /// Moves a file to a destination ///</summary> ///<param name="destination">the new location of the file</param> public File To(string destination) { if (_fileSystemWrapper.DirectoryExists(destination)) { destination = Path.Combine(destination, _file.FileName()); } FailableActionExecutor.DoAction(OnError, _fileSystemWrapper.MoveFile, _file.ToString(), destination); _file.Path = destination; return(_file); }
///<summary> /// Destination ///</summary> ///<param name="destination">The destination path</param> public void To(String destination) { string destinationFileName; string destinationDirectory; //if no filename in destination then get it from the source if (!Path.HasExtension(destination)) { destinationFileName = Path.GetFileName(_source.ToString()); destinationDirectory = destination; } else { destinationFileName = Path.GetFileName(destination); destinationDirectory = Path.GetDirectoryName(destination); } // ReSharper disable AssignNullToNotNullAttribute var dest = Path.Combine(destinationDirectory, destinationFileName); // ReSharper restore AssignNullToNotNullAttribute FailableActionExecutor.DoAction(base.OnError, _fileSystemWrapper.Copy, _source.ToString(), dest); }