mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2025-06-05 17:14:23 -04:00
Generate file name if given output path CLI argument is a directory
Closes #67
This commit is contained in:
parent
bd9dc6455f
commit
614bd8590d
2 changed files with 8 additions and 2 deletions
|
@ -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…
Add table
Add a link
Reference in a new issue