diff --git a/src/Cake.Common/IO/FileCopier.cs b/src/Cake.Common/IO/FileCopier.cs index 2703a089b3..3bff853759 100644 --- a/src/Cake.Common/IO/FileCopier.cs +++ b/src/Cake.Common/IO/FileCopier.cs @@ -166,14 +166,14 @@ private static void CopyFileCore(ICakeContext context, FilePath filePath, FilePa var file = context.FileSystem.GetFile(absoluteFilePath); // Get the parent folder structure and create it. - var newRelativeFolderPath = filePath.GetDirectory().ToString().Replace(commonPath.Replace("\\", "/"), string.Empty); - var newTargetPath = absoluteTargetPath.GetDirectory() + newRelativeFolderPath; - var newAbsoluteTargetPath = newTargetPath + @"/" + filePath.GetFilename(); + var newRelativeFolderPath = context.Directory(commonPath).Path.GetRelativePath(filePath.GetDirectory()); + var newTargetPath = targetFilePath.GetDirectory().Combine(newRelativeFolderPath); + var newAbsoluteTargetPath = newTargetPath.CombineWithFilePath(filePath.GetFilename()); context.Log.Verbose("Copying file {0} to {1}", absoluteFilePath.GetFilename(), newAbsoluteTargetPath); - if (!Directory.Exists(newTargetPath)) + if (!context.DirectoryExists(newTargetPath)) { - Directory.CreateDirectory(newTargetPath); + context.CreateDirectory(newTargetPath); } file.Copy(newAbsoluteTargetPath, true);