Created
May 23, 2017 00:44
-
-
Save guardrex/6e91f66d4084022f0c8ca1e482bddf2e to your computer and use it in GitHub Desktop.
Title fixes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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