public static Copy ( Stream source, Stream target ) : void | ||
source | Stream | Source stream |
target | Stream | Target stream |
return | void |
/// <summary> /// Copy a file to a target directory /// </summary> /// <param name="name">Name of the file</param> /// <param name="target">Target file system directory</param> /// <param name="targetName">Name (relative path) in the target directory</param> public void CopyFile(string name, IFileSystemDirectory target, string targetName) { var localTarget = target as LocalFileSystemDirectory; if (localTarget != null) { var targetSubdir = Path.GetDirectoryName(targetName); if (!String.IsNullOrWhiteSpace(targetSubdir)) { var absoluteTargetDir = Path.Combine(localTarget.AbsolutePath, targetSubdir); if (!Directory.Exists(absoluteTargetDir)) { Directory.CreateDirectory(absoluteTargetDir); } } File.Copy(Path.Combine(path, name), Path.Combine(localTarget.AbsolutePath, targetName), overwrite: true); } else { using (var sourceStream = ReadBinaryFile(name)) using (var targetStream = target.CreateBinaryFileWithDirectories(targetName)) StreamOperations.Copy(sourceStream, targetStream); } }
/// <summary> /// Copy a file to a target directory /// </summary> /// <param name="name">Name of the file</param> /// <param name="target">Target file system directory</param> /// <param name="targetName">Name (relative path) in the target directory</param> public void CopyFile(string name, IFileSystemDirectory target, string targetName) { var localTarget = target as LocalFileSystemDirectory; if (localTarget != null) { var targetSubdir = Path.GetDirectoryName(targetName); if (!String.IsNullOrWhiteSpace(targetSubdir)) { var absoluteTargetDir = Path.Combine(localTarget.AbsolutePath, targetSubdir); if (!Directory.Exists(absoluteTargetDir)) { Directory.CreateDirectory(absoluteTargetDir); } } var copy = true; if (target.Exists(targetName)) { var sourceSize = GetFileSize(name); var targetSize = target.GetFileSize(targetName); var sourceDate = GetLastModifiedDate(name); var targetDate = target.GetLastModifiedDate(targetName); copy = sourceSize != targetSize || !sourceDate.Equals(targetDate); } if (copy) { File.Copy(Path.Combine(path, name), Path.Combine(localTarget.AbsolutePath, targetName), overwrite: true); } } else { using (var sourceStream = ReadBinaryFile(name)) using (var targetStream = target.CreateBinaryFileWithDirectories(targetName)) StreamOperations.Copy(sourceStream, targetStream); } }