Generate file name if given output path CLI argument is a directory

Closes #67
pull/92/head
Alexey Golub 7 years ago
parent bd9dc6455f
commit 614bd8590d

@ -38,9 +38,9 @@ namespace DiscordChatExporter.Cli.Verbs
// Generate file path if not set
var filePath = Options.FilePath;
if (filePath.IsBlank())
if (filePath == null || filePath.EndsWith("/") || filePath.EndsWith("\\"))
{
filePath = $"{guild.Name} - {channel.Name}.{Options.ExportFormat.GetFileExtension()}"
filePath += $"{guild.Name} - {channel.Name}.{Options.ExportFormat.GetFileExtension()}"
.Replace(Path.GetInvalidFileNameChars(), '_');
}

@ -2,6 +2,7 @@
using DiscordChatExporter.Core.Models;
using Scriban;
using Scriban.Runtime;
using Tyrrrz.Extensions;
namespace DiscordChatExporter.Core.Services
{
@ -37,6 +38,11 @@ namespace DiscordChatExporter.Core.Services
var templateModel = new TemplateModel(format, log, _settingsService.DateFormat);
context.PushGlobal(templateModel.GetScriptObject());
// Create directory
var dirPath = Path.GetDirectoryName(filePath);
if (dirPath.IsNotBlank())
Directory.CreateDirectory(dirPath);
// Render output
using (var output = File.CreateText(filePath))
{

Loading…
Cancel
Save