DeleteFirst testing
This commit is contained in:
parent
fb9289a572
commit
fe524b7536
@ -161,6 +161,47 @@ internal static partial class Helper20241224
|
||||
}
|
||||
}
|
||||
|
||||
private static ReadOnlyDictionary<string, List<FileInfo>> GetKeyValuePairs(string directory, string searchPattern, string split)
|
||||
{
|
||||
string key;
|
||||
List<FileInfo>? collection;
|
||||
Dictionary<string, List<FileInfo>> results = [];
|
||||
string[] files = Directory.GetFiles(directory, searchPattern, SearchOption.TopDirectoryOnly);
|
||||
FileInfo[] fileInfoCollection = files.Select(l => new FileInfo(l)).ToArray();
|
||||
foreach (FileInfo fileInfo in fileInfoCollection.OrderBy(l => l.LastWriteTime))
|
||||
{
|
||||
key = fileInfo.Name.Split(split)[0];
|
||||
if (!results.TryGetValue(key, out collection))
|
||||
{
|
||||
results.Add(key, []);
|
||||
if (!results.TryGetValue(key, out collection))
|
||||
throw new Exception();
|
||||
}
|
||||
collection.Add(fileInfo);
|
||||
}
|
||||
return results.AsReadOnly();
|
||||
}
|
||||
|
||||
private static void DeleteFirst(string directory)
|
||||
{
|
||||
string checkFile;
|
||||
FileInfo fileInfo;
|
||||
ReadOnlyDictionary<string, List<FileInfo>> keyValuePairs = GetKeyValuePairs(directory, "*.tar", $"-{DateTime.Now.Year}-");
|
||||
foreach (KeyValuePair<string, List<FileInfo>> keyValuePair in keyValuePairs)
|
||||
{
|
||||
if (keyValuePair.Value.Count < 3)
|
||||
continue;
|
||||
for (int i = 1; i < keyValuePair.Value.Count - 1; i++)
|
||||
{
|
||||
fileInfo = keyValuePair.Value[i];
|
||||
checkFile = Path.Combine($"{fileInfo.Directory}-Delete", fileInfo.Name);
|
||||
if (File.Exists(checkFile))
|
||||
continue;
|
||||
File.Move(fileInfo.FullName, checkFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal static void Compare(ILogger<Worker> logger, List<string> args)
|
||||
{
|
||||
string host = args[2];
|
||||
@ -168,6 +209,7 @@ internal static partial class Helper20241224
|
||||
string format = NginxFileSystem.GetFormat();
|
||||
TimeZoneInfo timeZoneInfo = TimeZoneInfo.Local;
|
||||
string compareDirectory = Path.GetFullPath(args[0]);
|
||||
DeleteFirst(compareDirectory);
|
||||
logger.LogInformation("Comparing files on {host}", host);
|
||||
ReadOnlyCollection<Record> records = GetRecord(format, timeZoneInfo, host, new([rootDirectoryName]), compareDirectory);
|
||||
#if ShellProgressBar
|
||||
|
Loading…
x
Reference in New Issue
Block a user