Rename questions
This commit is contained in:
parent
b28db0abab
commit
f380a7ec20
@ -108,8 +108,6 @@ public class Configuration : Shared.Models.Properties.IPropertyConfiguration
|
||||
throw new NullReferenceException(nameof(propertyConfiguration.ValidMetadataExtensions));
|
||||
if (propertyConfiguration.VerifyToSeason is null || !propertyConfiguration.VerifyToSeason.Any())
|
||||
throw new NullReferenceException(nameof(propertyConfiguration.VerifyToSeason));
|
||||
if (Path.GetPathRoot(propertyConfiguration.RootDirectory) == propertyConfiguration.RootDirectory)
|
||||
throw new NullReferenceException(nameof(propertyConfiguration.RootDirectory));
|
||||
if (propertyConfiguration is null)
|
||||
throw new NullReferenceException(nameof(propertyConfiguration));
|
||||
if (string.IsNullOrEmpty(propertyConfiguration.DateGroup))
|
||||
|
@ -52,7 +52,7 @@ public class Rename
|
||||
Rename2000(matchNginxCollection);
|
||||
else if (matchNginxCollection.Any())
|
||||
{
|
||||
List<string> lines = RenameFilesInDirectories(options, matchNginxCollection);
|
||||
List<string> lines = RenameFilesInDirectories(log, options, matchNginxCollection);
|
||||
File.WriteAllLines($"D:/Tmp/Phares/{DateTime.Now.Ticks}.tsv", lines);
|
||||
if (comparePathRoot != Path.GetPathRoot(matchNginxCollection[0].ConvertedPath))
|
||||
_ = Shared.Models.Stateless.Methods.IPath.DeleteEmptyDirectories(comparePathRoot);
|
||||
@ -261,13 +261,15 @@ public class Rename
|
||||
}
|
||||
}
|
||||
|
||||
private void CopyInstead(List<(FileHolder, string)> toDoCollection)
|
||||
private List<string> CopyInstead(ILogger log, List<(FileHolder, string)> verifiedToDoCollection)
|
||||
{
|
||||
List<string> results = new();
|
||||
string copyTo;
|
||||
string? directory;
|
||||
ConsoleKey? consoleKey = null;
|
||||
List<string> distinctDirectories = new();
|
||||
List<(FileHolder, string)> copyCollection = new();
|
||||
foreach ((FileHolder fileHolder, string to) in toDoCollection)
|
||||
foreach ((FileHolder fileHolder, string to) in verifiedToDoCollection)
|
||||
{
|
||||
copyTo = $"{_AppSettings.CopyTo}{to[1..]}";
|
||||
directory = Path.GetDirectoryName(copyTo);
|
||||
@ -279,15 +281,58 @@ public class Rename
|
||||
distinctDirectories.Add(directory);
|
||||
}
|
||||
CreateDirectories(distinctDirectories);
|
||||
foreach ((FileHolder fileHolder, string to) in copyCollection)
|
||||
log.Information($"Ready to Copy {verifiedToDoCollection.Count} file(s)?");
|
||||
for (int y = 0; y < int.MaxValue; y++)
|
||||
{
|
||||
if (File.Exists(to))
|
||||
continue;
|
||||
File.Copy(fileHolder.FullName, to);
|
||||
log.Information("Press \"Y\" key to copy file(s), \"N\" key to log file(s) or close console to not copy 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 Copied!");
|
||||
else
|
||||
{
|
||||
foreach ((FileHolder fileHolder, string to) in verifiedToDoCollection)
|
||||
{
|
||||
results.Add(fileHolder.NameWithoutExtension);
|
||||
File.Copy(fileHolder.FullName, to);
|
||||
}
|
||||
log.Information("Done Copying");
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
private List<string> RenameFilesInDirectories(ProgressBarOptions options, MatchNginx[] matchNginxCollection)
|
||||
private static List<string> Move(ILogger log, List<(FileHolder, string)> verifiedToDoCollection)
|
||||
{
|
||||
List<string> results = new();
|
||||
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
|
||||
{
|
||||
foreach ((FileHolder fileHolder, string to) in verifiedToDoCollection)
|
||||
{
|
||||
results.Add(fileHolder.NameWithoutExtension);
|
||||
File.Move(fileHolder.FullName, to);
|
||||
File.WriteAllText($"{to}.id", $"{to}{Environment.NewLine}{fileHolder.FullName}");
|
||||
}
|
||||
log.Information("Done Moving");
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
private List<string> RenameFilesInDirectories(ILogger log, ProgressBarOptions options, MatchNginx[] matchNginxCollection)
|
||||
{
|
||||
List<string> results = new();
|
||||
string[] files;
|
||||
@ -296,6 +341,7 @@ public class Rename
|
||||
ProgressBar progressBar;
|
||||
List<string> distinctCollection = new();
|
||||
List<(FileHolder, string)> toDoCollection;
|
||||
List<(FileHolder, string)> verifiedToDoCollection;
|
||||
List<string> allFiles = GetAllFiles(matchNginxCollection);
|
||||
for (int i = 1; i < 3; i++)
|
||||
{
|
||||
@ -315,19 +361,19 @@ public class Rename
|
||||
distinctCount = distinctCollection.Count;
|
||||
if (toDoCollection.Count != distinctCount)
|
||||
continue;
|
||||
if (!string.IsNullOrEmpty(_AppSettings.CopyTo))
|
||||
CopyInstead(toDoCollection);
|
||||
else
|
||||
verifiedToDoCollection = new();
|
||||
foreach ((FileHolder fileHolder, string to) in toDoCollection)
|
||||
{
|
||||
foreach ((FileHolder fileHolder, string to) in toDoCollection)
|
||||
{
|
||||
results.Add(fileHolder.NameWithoutExtension);
|
||||
if (File.Exists(to))
|
||||
continue;
|
||||
File.Move(fileHolder.FullName, to);
|
||||
File.WriteAllText($"{to}.id", $"{to}{Environment.NewLine}{fileHolder.FullName}");
|
||||
}
|
||||
if (File.Exists(to))
|
||||
continue;
|
||||
verifiedToDoCollection.Add(new(fileHolder, to));
|
||||
}
|
||||
if (!verifiedToDoCollection.Any())
|
||||
continue;
|
||||
if (string.IsNullOrEmpty(_AppSettings.CopyTo))
|
||||
results.AddRange(Move(log, toDoCollection));
|
||||
else
|
||||
results.AddRange(CopyInstead(log, toDoCollection));
|
||||
progressBar.Dispose();
|
||||
}
|
||||
return results;
|
||||
|
Loading…
x
Reference in New Issue
Block a user