private void ManipulateFile(Action<MyFileInfo, string> fileAction, MyFileInfo file, string destinationPath, bool force = false) { var destination = _fileSystem.DirectoryInfo.FromDirectoryName(destinationPath); if (!destination.Exists && !force) throw new IOException(string.Format("The system cannot find the path specified. {0}", destinationPath)); var destinationFullName = _fileSystem.Path.Combine(destinationPath, file.RelativePath); var destinationFile = _fileSystem.FileInfo.FromFileName(destinationFullName); if (!destinationFile.Directory.Exists) { CreateDirectory(destinationFile.Directory.FullName); } fileAction(file, destinationFullName); }
public void CopyFile(MyFileInfo file, string destinationPath, bool overwrite = false, bool force = false) { var copyFile = new Action<MyFileInfo, string>((f, destinationFullPath) => f.File.CopyTo(destinationFullPath, overwrite)); ManipulateFile(copyFile, file, destinationPath, force); }
public void MoveFile(MyFileInfo file, string destinationPath, bool force = false) { var moveFile = new Action<MyFileInfo, string>((f, destinationFullPath) => f.File.MoveTo(destinationFullPath)); ManipulateFile(moveFile, file, destinationPath, force); }