-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
38 lines (30 loc) · 1.38 KB
/
Program.cs
File metadata and controls
38 lines (30 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using CommandLine;
using ConvertAll;
using LearnDocUtils;
CommandLineOptions options = null;
new Parser(cfg => { cfg.HelpWriter = Console.Error; cfg.CaseInsensitiveEnumValues = true; })
.ParseArguments<CommandLineOptions>(args)
.WithParsed(clo => options = clo);
if (options == null)
return; // bad arguments or help.
Console.WriteLine($"ConvertAll: using folder {Path.GetFileName(options.InputFolder)}");
if (!Directory.Exists(options.InputFolder))
{
Console.WriteLine($"{options.InputFolder} does not exist.");
return;
}
if (!Directory.Exists(options.OutputFolder))
Directory.CreateDirectory(options.OutputFolder);
foreach (var index in Directory.GetFiles(options.InputFolder, "index.yml", SearchOption.AllDirectories))
{
string folder = Path.GetDirectoryName(index) ?? "";
if (Directory.GetFiles(folder).Length < 2) // skip learning paths
continue;
string filename = Path.GetFileName(folder);
Console.WriteLine($"Processing {filename}");
string fullDocPath = Path.Combine(options.OutputFolder, Path.ChangeExtension(filename, "docx"));
if (File.Exists(fullDocPath))
File.Delete(fullDocPath);
var results = await LearnToDocx.ConvertFromFolderAsync("", folder, fullDocPath, new DocumentOptions { Debug = options.Debug });
File.WriteAllText(Path.ChangeExtension(fullDocPath, ".txt"), string.Join(Environment.NewLine, results));
}