From 846908d3f4c89832ee3ca5edef284791208d13e8 Mon Sep 17 00:00:00 2001 From: Mike Phares Date: Wed, 21 May 2025 22:29:02 -0700 Subject: [PATCH] match-directory --- .vscode/launch.json | 6 ++++++ ADO2025/PI6/Helper-2025-05-21.cs | 35 ++++++++++++++++++++++++++++++++ Day/HelperDay.cs | 2 ++ 3 files changed, 43 insertions(+) create mode 100644 ADO2025/PI6/Helper-2025-05-21.cs diff --git a/.vscode/launch.json b/.vscode/launch.json index e3e9a60..e7a0d19 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -11,6 +11,12 @@ "preLaunchTask": "build", "program": "${workspaceFolder}/bin/Debug/net8.0/win-x64/File-Folder-Helper.dll", "args": [ + "s", + "X", + "D:/5-Other-Small/Proxmox/ffnm", + "Day-Helper-2025-05-21", + "*.pdf", + "*.md", "s", "X", "D:/Tmp/phares/VisualStudioCode", diff --git a/ADO2025/PI6/Helper-2025-05-21.cs b/ADO2025/PI6/Helper-2025-05-21.cs new file mode 100644 index 0000000..2c21c31 --- /dev/null +++ b/ADO2025/PI6/Helper-2025-05-21.cs @@ -0,0 +1,35 @@ + +using Microsoft.Extensions.Logging; + +namespace File_Folder_Helper.ADO2025.PI6; + +internal static partial class Helper20250521 { + + private record Record(string Directory, string FileNameWithoutExtension); + + internal static void MatchDirectory(ILogger logger, List args) { + Record record; + string[] files; + string checkFile; + string searchPattern = args[2]; + string fileNameWithoutExtension; + string searchPatternB = args[3]; + Dictionary keyValuePairs = []; + string sourceDirectory = Path.GetFullPath(args[0].Split('~')[0]); + files = Directory.GetFiles(sourceDirectory, searchPattern, SearchOption.AllDirectories); + foreach (string file in files) { + keyValuePairs.Add(Path.GetFileNameWithoutExtension(file), Path.GetDirectoryName(file)); + } + files = Directory.GetFiles(sourceDirectory, searchPatternB, SearchOption.AllDirectories); + foreach (string file in files) { + fileNameWithoutExtension = Path.GetFileNameWithoutExtension(file); + if (!keyValuePairs.TryGetValue(fileNameWithoutExtension, out string? match)) + continue; + checkFile = Path.Combine(match, Path.GetFileName(file)); + if (File.Exists(checkFile)) + continue; + File.Move(file, checkFile); + } + } + +} \ No newline at end of file diff --git a/Day/HelperDay.cs b/Day/HelperDay.cs index 8bbe1db..e54f274 100644 --- a/Day/HelperDay.cs +++ b/Day/HelperDay.cs @@ -163,6 +163,8 @@ internal static class HelperDay ADO2025.PI5.Helper20250505.HyperTextMarkupLanguageToPortableDocumentFormat(logger, args); else if (args[1] == "Day-Helper-2025-05-19") ADO2025.PI6.Helper20250519.LiveSync(logger, args); + else if (args[1] == "Day-Helper-2025-05-21") + ADO2025.PI6.Helper20250521.MatchDirectory(logger, args); else throw new Exception(appSettings.Company); }