Move to Archive
This commit is contained in:
parent
a156ff8dcb
commit
dd4a16117c
12
.vscode/launch.json
vendored
12
.vscode/launch.json
vendored
@ -11,6 +11,18 @@
|
|||||||
"preLaunchTask": "build",
|
"preLaunchTask": "build",
|
||||||
"program": "${workspaceFolder}/bin/Debug/net8.0/win-x64/File-Folder-Helper.dll",
|
"program": "${workspaceFolder}/bin/Debug/net8.0/win-x64/File-Folder-Helper.dll",
|
||||||
"args": [
|
"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",
|
"s",
|
||||||
"X",
|
"X",
|
||||||
"D:/5-Other-Small/Kanban-mestsa003/{}/2025/2025_Week_05/223065",
|
"D:/5-Other-Small/Kanban-mestsa003/{}/2025/2025_Week_05/223065",
|
||||||
|
75
ADO2025/PI5/Helper-2025-02-18.cs
Normal file
75
ADO2025/PI5/Helper-2025-02-18.cs
Normal file
@ -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<Worker> 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<Worker> logger, List<string> 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
|
@ -133,6 +133,8 @@ internal static class HelperDay
|
|||||||
ADO2025.PI4.Helper20250126.Move(logger, args);
|
ADO2025.PI4.Helper20250126.Move(logger, args);
|
||||||
else if (args[1] == "Day-Helper-2025-02-04")
|
else if (args[1] == "Day-Helper-2025-02-04")
|
||||||
ADO2025.PI4.Helper20250204.ExtractKanban(logger, args);
|
ADO2025.PI4.Helper20250204.ExtractKanban(logger, args);
|
||||||
|
else if (args[1] == "Day-Helper-2025-02-18")
|
||||||
|
ADO2025.PI5.Helper20250218.MoveToArchive(logger, args);
|
||||||
else
|
else
|
||||||
throw new Exception(appSettings.Company);
|
throw new Exception(appSettings.Company);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user