ImgMetadataRemover/ConsoleInterface/FileSystemHelpers.cs

40 lines
1.3 KiB
C#
Raw Normal View History

using System.IO;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
2022-04-02 14:22:42 +00:00
namespace ConsoleInterface
{
public static class FileSystemHelpers
{
public static ILogger Logger = NullLogger.Instance;
2022-04-02 14:22:42 +00:00
/// <summary>
2022-04-02 14:22:42 +00:00
/// Creates the directory if it doesn't exist.
/// </summary>
/// <param name="directoryPath">The destination directory's path.</param>
public static void CreateDestinationDirectory(string directoryPath)
{
2022-04-02 14:33:48 +00:00
if (Directory.Exists(directoryPath))
{
return;
}
Logger.LogWarning("Output directory does not exist. Creating.");
Directory.CreateDirectory(directoryPath);
}
/// <summary>
2022-04-02 14:22:42 +00:00
/// CheckIfFileExists checks if file exists.
/// </summary>
/// <param name="filePath">The path of the file to be checked.</param>
/// <returns>Returns true if file exists, False otherwise.</returns>
public static bool CheckIfFileExists(string filePath)
{
var result = File.Exists(filePath);
Logger.LogDebug(result
? $"CheckIfFileExists - {filePath} exists."
: $"CheckIfFileExists - {filePath} doesn't exists.");
return result;
}
}
}