person-key-to-immich-import birthday json (Day-Helper-2024-05-18)
csharp_prefer_braces = true
This commit is contained in:
@ -5,41 +5,6 @@ namespace File_Folder_Helper.ADO2025.PI4;
|
||||
|
||||
internal static partial class Helper20250101 {
|
||||
|
||||
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 MoveToDelete(ILogger<Worker> logger, string appendage, ReadOnlyDictionary<string, List<FileInfo>> keyValuePairs) {
|
||||
string checkFile;
|
||||
FileInfo fileInfo;
|
||||
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}{appendage}", fileInfo.Name);
|
||||
if (File.Exists(checkFile))
|
||||
continue;
|
||||
logger.LogInformation("Moving <{fileInfo.FullName}> to <{checkFile}>", fileInfo.FullName, checkFile);
|
||||
File.Move(fileInfo.FullName, checkFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal static void MoveToDelete(ILogger<Worker> logger, List<string> args) {
|
||||
string split = args[3];
|
||||
string appendage = args[4];
|
||||
@ -50,4 +15,42 @@ internal static partial class Helper20250101 {
|
||||
MoveToDelete(logger, appendage, keyValuePairs);
|
||||
}
|
||||
|
||||
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 MoveToDelete(ILogger<Worker> logger, string appendage, ReadOnlyDictionary<string, List<FileInfo>> keyValuePairs) {
|
||||
string checkFile;
|
||||
FileInfo fileInfo;
|
||||
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}{appendage}", fileInfo.Name);
|
||||
if (File.Exists(checkFile)) {
|
||||
continue;
|
||||
}
|
||||
logger.LogInformation("Moving <{fileInfo.FullName}> to <{checkFile}>", fileInfo.FullName, checkFile);
|
||||
File.Move(fileInfo.FullName, checkFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user