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": [
|
||||
"s",
|
||||
"X",
|
||||
"L:/DevOps/Mesa_FI/File-Folder-Helper/.vscode/helper/tfs",
|
||||
"Day-Helper-2024-08-30",
|
||||
"MES",
|
||||
"https://tfs.intra.infineon.com",
|
||||
"/tfs/FactoryIntegration",
|
||||
"ART SPS",
|
||||
"/0d06e969-e1f5-4835-a359-620d557c7595/_apis/wit",
|
||||
"/wiql/3373b300-8de3-4301-9795-e990c3b226f9",
|
||||
"4n7d2jcql6bkq32f66tohddonfxajkypq66lm5y3zqemtlohawsa",
|
||||
"FI Backlog Mesa - Request List.json"
|
||||
"\\\\mesfs.infineon.com\\EC_EAFLog\\Staging\\Logs\\EAF-Info-Warn-002-020-010\\T41",
|
||||
"Day-Helper-2024-09-10",
|
||||
"*.log*",
|
||||
"333",
|
||||
"444",
|
||||
"555",
|
||||
"666",
|
||||
"777",
|
||||
"888",
|
||||
"999"
|
||||
],
|
||||
"cwd": "${workspaceFolder}",
|
||||
"console": "integratedTerminal",
|
||||
|
@ -99,6 +99,8 @@ internal static class HelperDay
|
||||
Day.Q32024.Helper20240828.MoveWaferCounterToArchive(logger, args);
|
||||
else if (args[1] == "Day-Helper-2024-08-30")
|
||||
Day.Q32024.Helper20240830.CompareWorkItems(logger, args);
|
||||
else if (args[1] == "Day-Helper-2024-09-10")
|
||||
Day.Q32024.Helper20240910.MoveFilesToWeekOfYear(logger, args);
|
||||
else
|
||||
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