From b525d29f9c1ee6b68b1f336417711779e5d0da34 Mon Sep 17 00:00:00 2001 From: Mike Phares Date: Tue, 20 Aug 2024 21:00:16 -0700 Subject: [PATCH] Ready to test MoveFilesWithSleep --- .vscode/launch.json | 15 ++++++++----- Day/HelperDay.cs | 2 ++ Day/Q32024/Helper-2024-08-20.cs | 39 +++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 5 deletions(-) create mode 100644 Day/Q32024/Helper-2024-08-20.cs diff --git a/.vscode/launch.json b/.vscode/launch.json index 2da0b5c..1c003fc 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -13,11 +13,16 @@ "args": [ "s", "X", - "L:/DevOps/Mesa_FI/File-Folder-Helper/.vscode/helper/2024-01-13", - "Day-Helper-2023-11-30", - "yyMMddhhmmssfff", - "\"SystemState\"", - "\\\\mesfs.infineon.com\\EC_APC\\Staging\\Traces\\DEP08CEPIEPSILON\\Test\\1762-T27\\2024-01-13", + "\\\\mesfs.infineon.com\\EC_SPC_Si\\PDSF\\MET08RESIHGCV\\Error", + "Day-Helper-2024-08-20", + "\\\\mesfs.infineon.com\\EC_SPC_Si\\PDSF\\MET08RESIHGCV\\Source", + "*.pdsf", + "5000", + "555", + "666", + "777", + "888", + "999" ], "cwd": "${workspaceFolder}", "console": "integratedTerminal", diff --git a/Day/HelperDay.cs b/Day/HelperDay.cs index 57bf775..d7be201 100644 --- a/Day/HelperDay.cs +++ b/Day/HelperDay.cs @@ -91,6 +91,8 @@ internal static class HelperDay Day.Q32024.Helper20240806.ArchiveFiles(logger, args); else if (args[1] == "Day-Helper-2024-08-09") Day.Q32024.Helper20240809.CreateWorkItems(logger, args); + else if (args[1] == "Day-Helper-2024-08-20") + Day.Q32024.Helper20240820.MoveFilesWithSleep(logger, args); else throw new Exception(appSettings.Company); } diff --git a/Day/Q32024/Helper-2024-08-20.cs b/Day/Q32024/Helper-2024-08-20.cs new file mode 100644 index 0000000..131713b --- /dev/null +++ b/Day/Q32024/Helper-2024-08-20.cs @@ -0,0 +1,39 @@ +using Microsoft.Extensions.Logging; +namespace File_Folder_Helper.Day.Q32024; + +internal static partial class Helper20240820 +{ + + internal static void MoveFilesWithSleep(ILogger logger, List args) + { + string checkFile; + string checkDirectory; + int sleep = int.Parse(args[4]); + string searchPattern = args[3]; + string sourceDirectory = args[0]; + string destinationDirectory = args[2]; + string source = Path.GetFullPath(sourceDirectory); + string[] files = Directory.GetFiles(source, "*", SearchOption.AllDirectories); + logger.LogInformation("With search pattern '{SearchPattern}' found {files}", searchPattern, files.Length); + foreach (string file in files) + { + Thread.Sleep(500); + checkFile = file.Replace(source, destinationDirectory); + if (checkFile == file) + throw new NotSupportedException("Replace failed!"); + checkDirectory = Path.GetDirectoryName(checkFile) ?? throw new NotSupportedException(); + try + { + if (!Directory.Exists(checkDirectory)) + _ = Directory.CreateDirectory(checkDirectory); + if (File.Exists(checkFile)) + continue; + File.Move(file, checkFile); + Thread.Sleep(sleep); + } + catch (Exception ex) + { logger.LogInformation(ex, "Inner loop error!"); } + } + } + +} \ No newline at end of file