2022-02-12 19:45:59 +00:00
|
|
|
|
using System.IO;
|
2022-02-11 21:39:34 +00:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using Microsoft.Extensions.Logging.Abstractions;
|
|
|
|
|
|
2022-04-02 14:22:42 +00:00
|
|
|
|
namespace ConsoleInterface
|
2022-02-11 21:39:34 +00:00
|
|
|
|
{
|
|
|
|
|
public static class FileSystemHelpers
|
|
|
|
|
{
|
|
|
|
|
public static ILogger Logger = NullLogger.Instance;
|
2022-04-02 14:22:42 +00:00
|
|
|
|
|
2022-02-11 21:39:34 +00:00
|
|
|
|
/// <summary>
|
2022-04-02 14:22:42 +00:00
|
|
|
|
/// Creates the directory if it doesn't exist.
|
2022-02-11 21:39:34 +00:00
|
|
|
|
/// </summary>
|
2022-02-12 19:45:59 +00:00
|
|
|
|
/// <param name="directoryPath">The destination directory's path.</param>
|
|
|
|
|
public static void CreateDestinationDirectory(string directoryPath)
|
2022-02-11 21:39:34 +00:00
|
|
|
|
{
|
2022-04-02 14:33:48 +00:00
|
|
|
|
if (Directory.Exists(directoryPath))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-12 19:45:59 +00:00
|
|
|
|
Logger.LogWarning("Output directory does not exist. Creating.");
|
|
|
|
|
Directory.CreateDirectory(directoryPath);
|
|
|
|
|
}
|
2022-02-11 21:39:34 +00:00
|
|
|
|
|
2022-02-12 19:45:59 +00:00
|
|
|
|
/// <summary>
|
2022-04-02 14:22:42 +00:00
|
|
|
|
/// CheckIfFileExists checks if file exists.
|
2022-02-12 19:45:59 +00:00
|
|
|
|
/// </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;
|
2022-02-11 21:39:34 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|