From dd4a16117ce3547513cd0c5c818e59865b2fdc72 Mon Sep 17 00:00:00 2001 From: Mike Phares Date: Wed, 19 Feb 2025 08:43:45 -0700 Subject: [PATCH] Move to Archive --- .vscode/launch.json | 12 +++++ ADO2025/PI5/Helper-2025-02-18.cs | 75 ++++++++++++++++++++++++++++++++ Day/HelperDay.cs | 2 + 3 files changed, 89 insertions(+) create mode 100644 ADO2025/PI5/Helper-2025-02-18.cs diff --git a/.vscode/launch.json b/.vscode/launch.json index 0431884..42f72ad 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -11,6 +11,18 @@ "preLaunchTask": "build", "program": "${workspaceFolder}/bin/Debug/net8.0/win-x64/File-Folder-Helper.dll", "args": [ + "s", + "X", + "D:/Tmp", + "Day-Helper-2025-02-18", + "*.pdsf", + "A_MES_ENTITY=", + "B_SEQUENCE=", + "\\\\mesfs.infineon.com\\EC_Characterization_Si\\Archive", + "666", + "777", + "888", + "999", "s", "X", "D:/5-Other-Small/Kanban-mestsa003/{}/2025/2025_Week_05/223065", diff --git a/ADO2025/PI5/Helper-2025-02-18.cs b/ADO2025/PI5/Helper-2025-02-18.cs new file mode 100644 index 0000000..6fb7e34 --- /dev/null +++ b/ADO2025/PI5/Helper-2025-02-18.cs @@ -0,0 +1,75 @@ +using Microsoft.Extensions.Logging; +using System.Globalization; + +namespace File_Folder_Helper.ADO2025.PI5; + +internal static partial class Helper20250218 +{ + + private static void MoveToArchive(ILogger logger, string searchMES, string searchSequence, string destinationRoot, string[] files) + { + string mes; + string text; + string sequence; + string checkFile; + string[] matches; + FileInfo fileInfo; + string weekOfYear; + string[] segments; + string[] segmentsB; + string[] segmentsC; + string checkDirectory; + Calendar calendar = new CultureInfo("en-US").Calendar; + foreach (string file in files) + { + fileInfo = new(file); + if (string.IsNullOrEmpty(fileInfo.DirectoryName)) + continue; + text = File.ReadAllText(file); + segments = text.Split(searchMES); + if (segments.Length < 2) + continue; + segmentsB = text.Split(searchSequence); + if (segmentsB.Length < 2) + continue; + mes = segments[1].Split(';')[0]; + sequence = segmentsB[1].Split(';')[0]; + segmentsC = Path.GetFileName(fileInfo.DirectoryName).Split('-'); + weekOfYear = $"{fileInfo.LastWriteTime.Year}_Week_{calendar.GetWeekOfYear(fileInfo.LastWriteTime, CalendarWeekRule.FirstDay, DayOfWeek.Sunday):00}"; + checkDirectory = Path.GetFullPath(Path.Combine(destinationRoot, mes, weekOfYear, fileInfo.LastWriteTime.ToString("yyyy-MM-dd"))); + if (!Directory.Exists(checkDirectory)) + { + logger.LogInformation("<{checkDirectory}>", checkDirectory); + continue; + } + matches = Directory.GetDirectories(checkDirectory, sequence, SearchOption.AllDirectories); + if (matches.Length != 1) + { + logger.LogInformation("!= 1 <{checkDirectory}>", checkDirectory); + continue; + } + checkFile = segmentsC.Length == 2 ? Path.Combine(matches[0], $"csv-{segmentsC[1]}-{fileInfo.Name}") : Path.Combine(matches[0], $"csv-{fileInfo.Name}"); + if (File.Exists(checkFile)) + { + logger.LogInformation("csv- {segmentsC} <{checkDirectory}>", segmentsC.Length, checkDirectory); + continue; + } + File.Move(fileInfo.FullName, checkFile); + } + } + + internal static void MoveToArchive(ILogger logger, List args) + { + string searchMES = args[3]; + string searchPattern = args[2]; + string searchSequence = args[4]; + string destinationRoot = args[5]; + string sourceDirectory = Path.GetFullPath(args[0]); + string[] files = Directory.GetFiles(sourceDirectory, searchPattern, SearchOption.AllDirectories); + logger.LogInformation("<{files}>(s)", files.Length); + MoveToArchive(logger, searchMES, searchSequence, destinationRoot, files); + } + +} + +// L:\DevOps\MESA_FI\file-folder-helper\bin\Debug\net8.0\win-x64>dotnet File-Folder-Helper.dll X D:/Tmp Day-Helper-2025-02-18 *.pdsf A_MES_ENTITY= B_SEQUENCE= \\mesfs.infineon.com\EC_Characterization_Si\Archive \ No newline at end of file diff --git a/Day/HelperDay.cs b/Day/HelperDay.cs index c874904..725c0b8 100644 --- a/Day/HelperDay.cs +++ b/Day/HelperDay.cs @@ -133,6 +133,8 @@ internal static class HelperDay ADO2025.PI4.Helper20250126.Move(logger, args); else if (args[1] == "Day-Helper-2025-02-04") ADO2025.PI4.Helper20250204.ExtractKanban(logger, args); + else if (args[1] == "Day-Helper-2025-02-18") + ADO2025.PI5.Helper20250218.MoveToArchive(logger, args); else throw new Exception(appSettings.Company); }