Last active
September 8, 2016 15:31
-
-
Save robmurrer/69b1d34483c98c9e9723c53fd6b77bcd to your computer and use it in GitHub Desktop.
This file contains hidden or 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.IO; | |
| using System.Collections.Generic; | |
| using System.Linq; | |
| using System.Text; | |
| using System.Threading.Tasks; | |
| using HeyRed.MarkdownSharp; | |
| namespace Artifact | |
| { | |
| class Program | |
| { | |
| static void Main(string[] args) | |
| { | |
| string path = GetWorkingDirectory(args); | |
| Console.WriteLine("Starting traversal in: " + path); | |
| Traverse(path, Markdowner); | |
| } | |
| static void Markdowner(FileInfo f) | |
| { | |
| if (Path.GetExtension(f.FullName) != ".txt") return; | |
| Markdown mark = new Markdown(); | |
| var html = mark.Transform(File.ReadAllText(f.FullName)); | |
| var outfile = File.CreateText(Path.ChangeExtension(f.FullName, ".html")); | |
| outfile.Write(html); | |
| outfile.Close(); | |
| } | |
| static void Traverse(string path, Action<FileInfo> action) | |
| { | |
| DirectoryInfo files = new DirectoryInfo(path); | |
| foreach (var d in files.EnumerateDirectories()) | |
| { | |
| Traverse(d.FullName, action); | |
| Console.WriteLine(d.FullName); | |
| foreach (var f in d.EnumerateFiles()) | |
| { | |
| Console.WriteLine(f.Name); | |
| action(f); | |
| } | |
| } | |
| foreach (var f in files.EnumerateFiles()) | |
| { | |
| Console.WriteLine(f.Name); | |
| action(f); | |
| } | |
| } | |
| private static string GetWorkingDirectory(string[] args) | |
| { | |
| string path = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); | |
| if (args.Length < 1) Console.WriteLine("Using application directory."); | |
| else if (!Directory.Exists(args[0])) Console.WriteLine("Directory does not exist: " + args[0]); | |
| else path = args[0]; | |
| return path; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment