static string GetTargetFile(string sourceFile, string rootDirectory) { var relativePath = FileEx.GetRelativePath(sourceFile, rootDirectory); var filtered = relativePath.Split(Path.DirectorySeparatorChar) .Where(x => !string.Equals(x, "mdsource", StringComparison.OrdinalIgnoreCase)) .ToArray(); var sourceTrimmed = Path.Combine(filtered); var targetFile = Path.Combine(rootDirectory, sourceTrimmed); // remove ".md" from ".source.md" then change ".source" to ".md" targetFile = Path.ChangeExtension(Path.ChangeExtension(targetFile, null), ".md"); return(targetFile); }