MoveFiles to Week of Year
This commit is contained in:
parent
fdb1e32c82
commit
db24568cb4
20
.vscode/launch.json
vendored
20
.vscode/launch.json
vendored
@ -13,16 +13,16 @@
|
|||||||
"args": [
|
"args": [
|
||||||
"s",
|
"s",
|
||||||
"X",
|
"X",
|
||||||
"L:/DevOps/Mesa_FI/File-Folder-Helper/.vscode/helper/tfs",
|
"\\\\mesfs.infineon.com\\EC_EAFLog\\Staging\\Logs\\EAF-Info-Warn-002-020-010\\T41",
|
||||||
"Day-Helper-2024-08-30",
|
"Day-Helper-2024-09-10",
|
||||||
"MES",
|
"*.log*",
|
||||||
"https://tfs.intra.infineon.com",
|
"333",
|
||||||
"/tfs/FactoryIntegration",
|
"444",
|
||||||
"ART SPS",
|
"555",
|
||||||
"/0d06e969-e1f5-4835-a359-620d557c7595/_apis/wit",
|
"666",
|
||||||
"/wiql/3373b300-8de3-4301-9795-e990c3b226f9",
|
"777",
|
||||||
"4n7d2jcql6bkq32f66tohddonfxajkypq66lm5y3zqemtlohawsa",
|
"888",
|
||||||
"FI Backlog Mesa - Request List.json"
|
"999"
|
||||||
],
|
],
|
||||||
"cwd": "${workspaceFolder}",
|
"cwd": "${workspaceFolder}",
|
||||||
"console": "integratedTerminal",
|
"console": "integratedTerminal",
|
||||||
|
@ -99,6 +99,8 @@ internal static class HelperDay
|
|||||||
Day.Q32024.Helper20240828.MoveWaferCounterToArchive(logger, args);
|
Day.Q32024.Helper20240828.MoveWaferCounterToArchive(logger, args);
|
||||||
else if (args[1] == "Day-Helper-2024-08-30")
|
else if (args[1] == "Day-Helper-2024-08-30")
|
||||||
Day.Q32024.Helper20240830.CompareWorkItems(logger, args);
|
Day.Q32024.Helper20240830.CompareWorkItems(logger, args);
|
||||||
|
else if (args[1] == "Day-Helper-2024-09-10")
|
||||||
|
Day.Q32024.Helper20240910.MoveFilesToWeekOfYear(logger, args);
|
||||||
else
|
else
|
||||||
throw new Exception(appSettings.Company);
|
throw new Exception(appSettings.Company);
|
||||||
}
|
}
|
||||||
|
39
Day/Q32024/Helper-2024-09-10.cs
Normal file
39
Day/Q32024/Helper-2024-09-10.cs
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using System.Globalization;
|
||||||
|
namespace File_Folder_Helper.Day.Q32024;
|
||||||
|
|
||||||
|
internal static partial class Helper20240910
|
||||||
|
{
|
||||||
|
|
||||||
|
internal static void MoveFilesToWeekOfYear(ILogger<Worker> logger, List<string> args)
|
||||||
|
{
|
||||||
|
string checkFile;
|
||||||
|
string weekOfYear;
|
||||||
|
string checkDirectory;
|
||||||
|
string searchPattern = args[2];
|
||||||
|
string sourceDirectory = args[0];
|
||||||
|
Calendar calendar = new CultureInfo("en-US").Calendar;
|
||||||
|
string[] files = Directory.GetFiles(sourceDirectory, searchPattern, SearchOption.AllDirectories);
|
||||||
|
logger.LogInformation("With search pattern '{SearchPattern}' found {files}", searchPattern, files.Length);
|
||||||
|
FileInfo[] collection = files.Select(l => new FileInfo(l)).ToArray();
|
||||||
|
foreach (FileInfo fileInfo in collection)
|
||||||
|
{
|
||||||
|
weekOfYear = $"{fileInfo.LastWriteTime.Year}_Week_{calendar.GetWeekOfYear(fileInfo.LastWriteTime, CalendarWeekRule.FirstDay, DayOfWeek.Sunday):00}";
|
||||||
|
checkDirectory = Path.Combine(sourceDirectory, weekOfYear, fileInfo.LastWriteTime.ToString("yyyy-MM-dd"));
|
||||||
|
if (!Directory.Exists(checkDirectory))
|
||||||
|
_ = Directory.CreateDirectory(checkDirectory);
|
||||||
|
checkFile = Path.Combine(checkDirectory, fileInfo.Name);
|
||||||
|
if (checkFile == fileInfo.FullName)
|
||||||
|
continue;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (File.Exists(checkFile))
|
||||||
|
continue;
|
||||||
|
File.Move(fileInfo.FullName, checkFile);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{ logger.LogInformation(ex, "Inner loop error!"); }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user