file-folder-helper/Day/Q42023/Helper-2023-11-08.cs
2024-08-09 09:54:22 -07:00

37 lines
1.2 KiB
C#

using Microsoft.Extensions.Logging;
namespace File_Folder_Helper.Day.Q42023;
internal static class Helper20231108
{
internal static void MasterImage(ILogger<Worker> logger, List<string> args)
{
string fileName;
string checkFile;
string[] aSegments;
string[] bSegments;
if (!Directory.Exists(args[0]))
throw new Exception(args[0]);
if (!Directory.Exists(args[2]))
throw new Exception(args[2]);
string directoryName = Path.GetFileName(args[0]) ?? throw new Exception();
string[] files = Directory.GetFiles(args[0]);
logger.LogInformation("{fileCount}", files.Length.ToString());
foreach (string file in files)
{
aSegments = Path.GetFileNameWithoutExtension(file).Split('-');
if (aSegments.Length != 2)
continue;
bSegments = aSegments[1].Split('_');
if (bSegments.Length != 3)
continue;
fileName = $"{directoryName}-{bSegments[1]}-{bSegments[0]}{Path.GetExtension(file)}";
checkFile = Path.Combine(args[2], fileName);
if (File.Exists(checkFile))
continue;
File.Copy(file, checkFile);
}
}
}