diff --git a/ConsoleInterface/Program.cs b/ConsoleInterface/Program.cs
index ee408d6..c8aa8d4 100644
--- a/ConsoleInterface/Program.cs
+++ b/ConsoleInterface/Program.cs
@@ -1,6 +1,8 @@
-using CommandLine;
+using System.IO;
+using CommandLine;
using Image;
using Microsoft.Extensions.Logging;
+using Microsoft.Extensions.Logging.Abstractions;
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable ClassNeverInstantiated.Global
@@ -10,6 +12,8 @@ namespace ConsoleInterface
{
internal static class Program
{
+ private static readonly ILogger Logger = NullLogger.Instance;
+
///
/// The console interface for the project and the main entrypoint.
///
@@ -30,6 +34,7 @@ namespace ConsoleInterface
OriginalFilenameFileOutputPathFormatter.Logger =
loggerFactory.CreateLogger(nameof(OriginalFilenameFileOutputPathFormatter));
+ CreateDestinationDirectory(options.DestinationDirectory);
var outputFormatter = OriginalFilenameFileOutputPathFormatter.Create(options.DestinationDirectory);
var executor = TaskExecutor.Create(new TaskExecutorOptions
{
@@ -42,6 +47,17 @@ namespace ConsoleInterface
executor.ParallelCleanImages(filesRetriever.GetFilenamesFromPath(options.SourceDirectory));
}
+ ///
+ /// Creates the directory if it doesn't exist.
+ ///
+ /// The destination directory.
+ private static void CreateDestinationDirectory(string destinationDirectory)
+ {
+ if (Directory.Exists(destinationDirectory)) return;
+ Logger.LogWarning("Output directory does not exist. Creating.");
+ Directory.CreateDirectory(destinationDirectory);
+ }
+
///
/// Options is a class defining command line options supported by this program.
///
diff --git a/ImageCore/OriginalFilenameFileOutputPathFormatter.cs b/ImageCore/OriginalFilenameFileOutputPathFormatter.cs
index 9921d5a..4e26e49 100644
--- a/ImageCore/OriginalFilenameFileOutputPathFormatter.cs
+++ b/ImageCore/OriginalFilenameFileOutputPathFormatter.cs
@@ -19,12 +19,6 @@ namespace Image
/// The output directory.
public OriginalFilenameFileOutputPathFormatter(string outputDirectory)
{
- if (!Directory.Exists(outputDirectory))
- {
- Logger.LogWarning("Output directory does not exists. Creating.");
- Directory.CreateDirectory(outputDirectory);
- }
-
_outputDirectory = outputDirectory;
}