Ready to test MoveFilesWithSleep
This commit is contained in:
parent
fd1ee79e75
commit
b525d29f9c
15
.vscode/launch.json
vendored
15
.vscode/launch.json
vendored
@ -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",
|
||||
|
@ -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);
|
||||
}
|
||||
|
39
Day/Q32024/Helper-2024-08-20.cs
Normal file
39
Day/Q32024/Helper-2024-08-20.cs
Normal 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!"); }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user