Ready to test MoveFilesWithSleep

This commit is contained in:
Mike Phares 2024-08-20 21:00:16 -07:00
parent fd1ee79e75
commit b525d29f9c
3 changed files with 51 additions and 5 deletions

15
.vscode/launch.json vendored
View File

@ -13,11 +13,16 @@
"args": [ "args": [
"s", "s",
"X", "X",
"L:/DevOps/Mesa_FI/File-Folder-Helper/.vscode/helper/2024-01-13", "\\\\mesfs.infineon.com\\EC_SPC_Si\\PDSF\\MET08RESIHGCV\\Error",
"Day-Helper-2023-11-30", "Day-Helper-2024-08-20",
"yyMMddhhmmssfff", "\\\\mesfs.infineon.com\\EC_SPC_Si\\PDSF\\MET08RESIHGCV\\Source",
"\"SystemState\"", "*.pdsf",
"\\\\mesfs.infineon.com\\EC_APC\\Staging\\Traces\\DEP08CEPIEPSILON\\Test\\1762-T27\\2024-01-13", "5000",
"555",
"666",
"777",
"888",
"999"
], ],
"cwd": "${workspaceFolder}", "cwd": "${workspaceFolder}",
"console": "integratedTerminal", "console": "integratedTerminal",

View File

@ -91,6 +91,8 @@ internal static class HelperDay
Day.Q32024.Helper20240806.ArchiveFiles(logger, args); Day.Q32024.Helper20240806.ArchiveFiles(logger, args);
else if (args[1] == "Day-Helper-2024-08-09") else if (args[1] == "Day-Helper-2024-08-09")
Day.Q32024.Helper20240809.CreateWorkItems(logger, args); Day.Q32024.Helper20240809.CreateWorkItems(logger, args);
else if (args[1] == "Day-Helper-2024-08-20")
Day.Q32024.Helper20240820.MoveFilesWithSleep(logger, args);
else else
throw new Exception(appSettings.Company); throw new Exception(appSettings.Company);
} }

View File

@ -0,0 +1,39 @@
using Microsoft.Extensions.Logging;
namespace File_Folder_Helper.Day.Q32024;
internal static partial class Helper20240820
{
internal static void MoveFilesWithSleep(ILogger<Worker> logger, List<string> 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!"); }
}
}
}