diff --git a/DiscordChatExporter.Cli/Verbs/ExportChatVerb.cs b/DiscordChatExporter.Cli/Verbs/ExportChatVerb.cs index a791f2d..8188517 100644 --- a/DiscordChatExporter.Cli/Verbs/ExportChatVerb.cs +++ b/DiscordChatExporter.Cli/Verbs/ExportChatVerb.cs @@ -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(), '_'); } diff --git a/DiscordChatExporter.Core/Services/ExportService.cs b/DiscordChatExporter.Core/Services/ExportService.cs index 15a17cd..0d623aa 100644 --- a/DiscordChatExporter.Core/Services/ExportService.cs +++ b/DiscordChatExporter.Core/Services/ExportService.cs @@ -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)) {