Metadata-Query
This commit is contained in:
@ -316,15 +316,14 @@ public class Rename
|
||||
private List<string> RenameFilesInDirectories(ILogger log)
|
||||
{
|
||||
List<string> results = new();
|
||||
string message;
|
||||
bool nefPresent;
|
||||
ConsoleKey? consoleKey;
|
||||
ProgressBar progressBar;
|
||||
const string fileSearchFilter = "*";
|
||||
string message = ") Renaming files";
|
||||
const string directorySearchFilter = "*";
|
||||
List<string> distinctDirectories = new();
|
||||
List<(FileHolder, string, string)> toDoCollection;
|
||||
List<(FileHolder, string)> verifiedToDoCollection;
|
||||
List<(FileHolder, string)> verifiedToDoCollection = new();
|
||||
List<(FileHolder, string, string)> toDoCollection = new();
|
||||
ProgressBarOptions options = new() { ProgressCharacter = '─', ProgressBarOnBottom = true, DisableBottomPercentage = true };
|
||||
List<string[]> filesCollection = Shared.Models.Stateless.Methods.IDirectory.GetFilesCollection(_PropertyConfiguration.RootDirectory, directorySearchFilter, fileSearchFilter);
|
||||
int count = filesCollection.Select(l => l.Length).Sum();
|
||||
@ -332,59 +331,65 @@ public class Rename
|
||||
{
|
||||
if (!files.Any())
|
||||
continue;
|
||||
// foreach (string file in files)
|
||||
// {
|
||||
// if (!file.EndsWith(".del"))
|
||||
// continue;
|
||||
// File.Move(file, file[..^4]);
|
||||
// }
|
||||
// continue;
|
||||
distinctDirectories.Clear();
|
||||
progressBar = new(count, message, options);
|
||||
message = $") Renaming files for <{files.FirstOrDefault()}>";
|
||||
progressBar = new(files.Length, message, options);
|
||||
if (_AppSettings.RenameUndo)
|
||||
toDoCollection = GetRenameUndoToDoCollection(progressBar, files);
|
||||
toDoCollection.AddRange(GetRenameUndoToDoCollection(progressBar, files));
|
||||
else
|
||||
{
|
||||
nefPresent = files.Any(l => l.EndsWith(".NEF"));
|
||||
if (!nefPresent)
|
||||
toDoCollection = GetToDoCollection(progressBar, files, nefPresent);
|
||||
toDoCollection.AddRange(GetToDoCollection(progressBar, files, nefPresent));
|
||||
else
|
||||
toDoCollection = GetToDoCollection(progressBar, (from l in files where l.EndsWith(".JPG") select l).ToArray(), nefPresent);
|
||||
toDoCollection.AddRange(GetToDoCollection(progressBar, (from l in files where l.EndsWith(".JPG") select l).ToArray(), nefPresent));
|
||||
}
|
||||
progressBar.Dispose();
|
||||
verifiedToDoCollection = new();
|
||||
foreach ((FileHolder fileHolder, string directory, string to) in toDoCollection)
|
||||
{
|
||||
if (distinctDirectories.Contains(directory))
|
||||
continue;
|
||||
distinctDirectories.Add(directory);
|
||||
}
|
||||
foreach (string distinctDirectory in distinctDirectories)
|
||||
{
|
||||
if (!Directory.Exists(distinctDirectory))
|
||||
_ = Directory.CreateDirectory(distinctDirectory);
|
||||
}
|
||||
foreach ((FileHolder fileHolder, string directory, string to) in toDoCollection)
|
||||
{
|
||||
if (File.Exists(to))
|
||||
continue;
|
||||
verifiedToDoCollection.Add(new(fileHolder, to));
|
||||
File.WriteAllText($"{to}.id", $"{to}{Environment.NewLine}{fileHolder.FullName}");
|
||||
}
|
||||
if (!verifiedToDoCollection.Any())
|
||||
}
|
||||
foreach ((FileHolder fileHolder, string directory, string to) in toDoCollection)
|
||||
{
|
||||
if (distinctDirectories.Contains(directory))
|
||||
continue;
|
||||
consoleKey = null;
|
||||
log.Information($"Ready to Move {verifiedToDoCollection.Count} file(s)?");
|
||||
for (int y = 0; y < int.MaxValue; y++)
|
||||
{
|
||||
log.Information("Press \"Y\" key to move file(s), \"N\" key to log file(s) or close console to not move files");
|
||||
consoleKey = System.Console.ReadKey().Key;
|
||||
if (consoleKey is ConsoleKey.Y or ConsoleKey.N)
|
||||
break;
|
||||
}
|
||||
log.Information(". . .");
|
||||
if (consoleKey is null || consoleKey.Value != ConsoleKey.Y)
|
||||
log.Information("Nothing moved!");
|
||||
else
|
||||
{
|
||||
progressBar = new(count, message, options);
|
||||
results.AddRange(Move(progressBar, verifiedToDoCollection));
|
||||
progressBar.Dispose();
|
||||
log.Information("Done Moving");
|
||||
}
|
||||
distinctDirectories.Add(directory);
|
||||
}
|
||||
foreach (string distinctDirectory in distinctDirectories)
|
||||
{
|
||||
if (!Directory.Exists(distinctDirectory))
|
||||
_ = Directory.CreateDirectory(distinctDirectory);
|
||||
}
|
||||
foreach ((FileHolder fileHolder, string directory, string to) in toDoCollection)
|
||||
{
|
||||
if (File.Exists(to))
|
||||
continue;
|
||||
verifiedToDoCollection.Add(new(fileHolder, to));
|
||||
File.WriteAllText($"{to}.id", $"{to}{Environment.NewLine}{fileHolder.FullName}");
|
||||
}
|
||||
ConsoleKey? consoleKey = null;
|
||||
log.Information($"Ready to Move {verifiedToDoCollection.Count} file(s)?");
|
||||
for (int y = 0; y < int.MaxValue; y++)
|
||||
{
|
||||
log.Information("Press \"Y\" key to move file(s), \"N\" key to log file(s) or close console to not move files");
|
||||
consoleKey = System.Console.ReadKey().Key;
|
||||
if (consoleKey is ConsoleKey.Y or ConsoleKey.N)
|
||||
break;
|
||||
}
|
||||
log.Information(". . .");
|
||||
if (consoleKey is null || consoleKey.Value != ConsoleKey.Y)
|
||||
log.Information("Nothing moved!");
|
||||
else
|
||||
{
|
||||
message = ") Renaming files";
|
||||
progressBar = new(count, message, options);
|
||||
results.AddRange(Move(progressBar, verifiedToDoCollection));
|
||||
progressBar.Dispose();
|
||||
log.Information("Done Moving");
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
Reference in New Issue
Block a user