free-file-sync-change-created-date
This commit is contained in:
parent
74e9fc33af
commit
d23f802cdb
6
.vscode/launch.json
vendored
6
.vscode/launch.json
vendored
@ -11,6 +11,12 @@
|
||||
"preLaunchTask": "build",
|
||||
"program": "${workspaceFolder}/bin/Debug/net8.0/win-x64/File-Folder-Helper.dll",
|
||||
"args": [
|
||||
"s",
|
||||
"X",
|
||||
"C:/Users/phares/AppData/Roaming/FreeFileSync",
|
||||
"Day-Helper-2025-04-21",
|
||||
"GlobalSettings.xml",
|
||||
"LastSync|Config",
|
||||
"s",
|
||||
"X",
|
||||
"L:/Tmp/MET08ANLYSDIFAAST230",
|
||||
|
47
ADO2025/PI5/Helper-2025-04-21.cs
Normal file
47
ADO2025/PI5/Helper-2025-04-21.cs
Normal file
@ -0,0 +1,47 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace File_Folder_Helper.ADO2025.PI5;
|
||||
|
||||
internal static partial class Helper20250421 {
|
||||
|
||||
internal static void FreeFileSyncChangeCreatedDate(ILogger<Worker> logger, List<string> args) {
|
||||
string searchPattern = args[2];
|
||||
string[] searchPatterns = args[3].Split('|');
|
||||
string sourceDirectory = Path.GetFullPath(args[0]);
|
||||
if (searchPatterns.Length != 2)
|
||||
throw new NotImplementedException($"Not the correct number of {searchPatterns} were passed!");
|
||||
string lastSyncSearch = $"{searchPatterns[0]}=\"";
|
||||
string configurationFileSearch = $"{searchPatterns[1]}=\"";
|
||||
string[] files = Directory.GetFiles(sourceDirectory, searchPattern, SearchOption.AllDirectories);
|
||||
if (files.Length != 1)
|
||||
logger.LogWarning("<{files}>(s)", files.Length);
|
||||
else
|
||||
ChangeCreatedDate(lastSyncSearch, configurationFileSearch, files[0]);
|
||||
}
|
||||
|
||||
private static void ChangeCreatedDate(string lastSyncSearch, string configurationFileSearch, string sourceFile) {
|
||||
long epoch;
|
||||
string lastSync;
|
||||
string[] segments;
|
||||
string[] segmentsB;
|
||||
DateTime creationTime;
|
||||
string configurationFile;
|
||||
string[] lines = File.ReadAllLines(sourceFile);
|
||||
foreach (string line in lines) {
|
||||
segments = line.Split(lastSyncSearch);
|
||||
if (segments.Length != 2)
|
||||
continue;
|
||||
segmentsB = line.Split(configurationFileSearch);
|
||||
if (segmentsB.Length != 2)
|
||||
continue;
|
||||
lastSync = segments[1].Split('"')[0];
|
||||
if (!long.TryParse(lastSync, out epoch) || epoch == 0)
|
||||
continue;
|
||||
configurationFile = segmentsB[1].Split('"')[0];
|
||||
if (!File.Exists(configurationFile))
|
||||
continue;
|
||||
creationTime = new(DateTimeOffset.UnixEpoch.AddSeconds(epoch).ToLocalTime().Ticks);
|
||||
File.SetCreationTime(configurationFile, creationTime);
|
||||
}
|
||||
}
|
||||
}
|
@ -155,6 +155,8 @@ internal static class HelperDay
|
||||
ADO2025.PI5.Helper20250404.KumaToGatus(logger, args);
|
||||
else if (args[1] == "Day-Helper-2025-04-07")
|
||||
ADO2025.PI5.Helper20250407.Sync(logger, args);
|
||||
else if (args[1] == "Day-Helper-2025-04-21")
|
||||
ADO2025.PI5.Helper20250421.FreeFileSyncChangeCreatedDate(logger, args);
|
||||
else
|
||||
throw new Exception(appSettings.Company);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user