Title fixes
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
using static System.IO.SearchOption; | |
namespace RemoveBlankLines | |
{ | |
class Program | |
{ | |
static void Main() | |
{ | |
string path = @"C:\Users\XXXXXXXX\Documents\GitHub\docs-1\docs\"; | |
var files = Directory.EnumerateFiles(path, "*.md", AllDirectories); | |
foreach (var file in files) | |
{ | |
var changed = false; | |
var inputLines = File.ReadAllLines(file); | |
var outputLines = new List<string>(); | |
foreach (var line in inputLines) | |
{ | |
var trimmedLine = line.Trim(); | |
if (trimmedLine.StartsWith("title:")) | |
{ | |
var noQuotesLine = trimmedLine.Replace("\"", string.Empty); | |
if (!noQuotesLine.EndsWith("Microsoft Docs")) | |
{ | |
outputLines.Add($"{noQuotesLine} | Microsoft Docs"); | |
changed = true; | |
} | |
else | |
{ | |
outputLines.Add(noQuotesLine); | |
} | |
} | |
else | |
{ | |
outputLines.Add(line); | |
} | |
} | |
if (changed) | |
{ | |
Console.WriteLine(file.Substring(path.Length)); | |
File.WriteAllLines(file, outputLines); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment