person-key-to-immich-import birthday json (Day-Helper-2024-05-18)
csharp_prefer_braces = true
This commit is contained in:
@ -1,8 +1,6 @@
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
using File_Folder_Helper.Helpers;
|
||||
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace File_Folder_Helper.ADO2025.PI5;
|
||||
|
||||
@ -21,14 +19,15 @@ internal static partial class Helper20250321 {
|
||||
bool check = searchPattern.Split('.').Length == 3;
|
||||
ReadOnlyCollection<ThreeDeep> collection = ThreeDeep.GetCollection(files);
|
||||
foreach (ThreeDeep threeDeep in collection) {
|
||||
if (!json && check)
|
||||
if (!json && check) {
|
||||
fileNameWithoutExtension = threeDeep.DirectoryName;
|
||||
else if (!json && !check)
|
||||
} else if (!json && !check) {
|
||||
fileNameWithoutExtension = threeDeep.FileNameWithoutExtension;
|
||||
else if (json)
|
||||
} else if (json) {
|
||||
fileNameWithoutExtension = Path.GetFileNameWithoutExtension(threeDeep.FileNameWithoutExtension);
|
||||
else
|
||||
} else {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
directory = $"{fileNameWithoutExtension[^1]}{fileNameWithoutExtension[^3..][..2]}";
|
||||
if (json || (!json && !check)) {
|
||||
record = new(Directory: Path.Combine(sourceDirectory, "new-a", directory),
|
||||
@ -38,13 +37,13 @@ internal static partial class Helper20250321 {
|
||||
record = new(Directory: Path.Combine(sourceDirectory, "new-b", directory, threeDeep.DirectoryName),
|
||||
File: $"{threeDeep.FileNameWithoutExtension}{threeDeep.Extension}",
|
||||
ThreeDeep: threeDeep);
|
||||
} else
|
||||
} else {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
results.Add(record);
|
||||
}
|
||||
return results.AsReadOnly();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private record ThreeDeep(string Extension,
|
||||
@ -83,17 +82,19 @@ internal static partial class Helper20250321 {
|
||||
internal static void MoveToLast(ILogger<Worker> logger, List<string> args) {
|
||||
string[] searchPatterns = args[2].Split('~');
|
||||
string sourceDirectory = Path.GetFullPath(args[0]);
|
||||
if (searchPatterns.Length == 1)
|
||||
if (searchPatterns.Length == 1) {
|
||||
logger.LogInformation("No code for just one!");
|
||||
else {
|
||||
} else {
|
||||
HelperDeleteEmptyDirectories.DeleteEmptyDirectories(logger, sourceDirectory);
|
||||
ReadOnlyCollection<Record> collection = GetCollection(logger, searchPatterns, sourceDirectory);
|
||||
if (collection.Count != 0)
|
||||
if (collection.Count != 0) {
|
||||
UseCollection(collection);
|
||||
else
|
||||
} else {
|
||||
logger.LogInformation("No files!");
|
||||
if (collection.Count != 0)
|
||||
}
|
||||
if (collection.Count != 0) {
|
||||
HelperDeleteEmptyDirectories.DeleteEmptyDirectories(logger, sourceDirectory);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -102,9 +103,9 @@ internal static partial class Helper20250321 {
|
||||
List<Record> results = [];
|
||||
foreach (string searchPattern in searchPatterns) {
|
||||
files = Directory.GetFiles(sourceDirectory, searchPattern, SearchOption.AllDirectories);
|
||||
if (files.Length == 0)
|
||||
if (files.Length == 0) {
|
||||
logger.LogWarning("<{files}>(s)", files.Length);
|
||||
else {
|
||||
} else {
|
||||
ReadOnlyCollection<Record> collection = Record.GetCollection(sourceDirectory, searchPattern, files);
|
||||
results.AddRange(collection);
|
||||
}
|
||||
@ -117,19 +118,22 @@ internal static partial class Helper20250321 {
|
||||
string checkFile;
|
||||
List<string> distinct = [];
|
||||
foreach (Record record in collection) {
|
||||
if (distinct.Contains(record.Directory))
|
||||
if (distinct.Contains(record.Directory)) {
|
||||
continue;
|
||||
}
|
||||
distinct.Add(record.Directory);
|
||||
}
|
||||
foreach (string directory in distinct) {
|
||||
if (Directory.Exists(directory))
|
||||
if (Directory.Exists(directory)) {
|
||||
continue;
|
||||
}
|
||||
_ = Directory.CreateDirectory(directory);
|
||||
}
|
||||
foreach (Record record in collection) {
|
||||
checkFile = Path.Combine(record.Directory, record.File);
|
||||
if (File.Exists(checkFile))
|
||||
if (File.Exists(checkFile)) {
|
||||
continue;
|
||||
}
|
||||
fullPath = ThreeDeep.GetFullPath(record.ThreeDeep);
|
||||
File.Move(fullPath, checkFile);
|
||||
}
|
||||
|
Reference in New Issue
Block a user