diff --git a/src/ModularPipelines/FileSystem/Folder.cs b/src/ModularPipelines/FileSystem/Folder.cs index 0a1c9e0321..5c1dd201b0 100644 --- a/src/ModularPipelines/FileSystem/Folder.cs +++ b/src/ModularPipelines/FileSystem/Folder.cs @@ -111,12 +111,16 @@ public Folder CopyTo(string targetPath) foreach (var dirPath in Directory.EnumerateDirectories(this, "*", SearchOption.AllDirectories)) { - Directory.CreateDirectory(dirPath.Replace(this, targetPath)); + var relativePath = System.IO.Path.GetRelativePath(this, dirPath); + var newPath = System.IO.Path.Combine(targetPath, relativePath); + Directory.CreateDirectory(newPath); } - foreach (var newPath in Directory.EnumerateFiles(this, "*", SearchOption.AllDirectories)) + foreach (var filePath in Directory.EnumerateFiles(this, "*", SearchOption.AllDirectories)) { - System.IO.File.Copy(newPath, newPath.Replace(this, targetPath), true); + var relativePath = System.IO.Path.GetRelativePath(this, filePath); + var newPath = System.IO.Path.Combine(targetPath, relativePath); + System.IO.File.Copy(filePath, newPath, true); } ModuleLogger.Current.LogInformation("Copying Folder: {Source} > {Destination}", this, targetPath);