Rename
This commit is contained in:
parent
79bcbf3487
commit
ba77635ddb
@ -98,6 +98,7 @@ public class Rename
|
||||
string[] lines;
|
||||
string fileName;
|
||||
FileHolder fileHolder;
|
||||
List<string> distinct = new();
|
||||
foreach (string file in files)
|
||||
{
|
||||
progressBar.Tick();
|
||||
@ -107,6 +108,9 @@ public class Rename
|
||||
lines = File.ReadAllLines(file);
|
||||
if (lines.Length < 2)
|
||||
continue;
|
||||
if (distinct.Contains(lines[1]))
|
||||
continue;
|
||||
distinct.Add(lines[1]);
|
||||
fileHolder = new(lines[0]);
|
||||
results.Add(new(fileHolder, lines[1]));
|
||||
}
|
||||
@ -117,6 +121,7 @@ public class Rename
|
||||
{
|
||||
List<(FileHolder, string)> results = new();
|
||||
int? id;
|
||||
string fileName;
|
||||
string? message;
|
||||
string checkFile;
|
||||
TimeSpan timeSpan;
|
||||
@ -128,6 +133,7 @@ public class Rename
|
||||
DateTime? minimumDateTime;
|
||||
const string jpg = ".jpg";
|
||||
const string jpeg = ".jpeg";
|
||||
List<string> distinct = new();
|
||||
bool isValidImageFormatExtension;
|
||||
bool nameWithoutExtensionIsIdFormat;
|
||||
IReadOnlyList<MetadataExtractor.Directory> directories;
|
||||
@ -140,6 +146,9 @@ public class Rename
|
||||
checkFile = file[..^4];
|
||||
if (File.Exists(checkFile))
|
||||
continue;
|
||||
if (distinct.Contains(checkFile))
|
||||
continue;
|
||||
distinct.Add(checkFile);
|
||||
results.Add(new(fileHolder, checkFile));
|
||||
continue;
|
||||
}
|
||||
@ -159,12 +168,24 @@ public class Rename
|
||||
checkFile = Path.Combine(fileHolder.DirectoryName, $"{fileHolder.NameWithoutExtension}{jpg}.id");
|
||||
if (File.Exists(checkFile))
|
||||
continue;
|
||||
if (distinct.Contains(checkFile))
|
||||
continue;
|
||||
distinct.Add(checkFile);
|
||||
results.Add(new(new($"{fileHolder.FullName}.id"), checkFile));
|
||||
}
|
||||
checkFile = Path.Combine(fileHolder.DirectoryName, $"{fileHolder.NameWithoutExtension}{jpg}");
|
||||
if (File.Exists(checkFile))
|
||||
continue;
|
||||
if (distinct.Contains(checkFile))
|
||||
continue;
|
||||
distinct.Add(checkFile);
|
||||
results.Add(new(fileHolder, checkFile));
|
||||
if (File.Exists(checkFile))
|
||||
continue;
|
||||
File.Move(fileHolder.FullName, checkFile);
|
||||
fileHolder = new(checkFile);
|
||||
if (fileHolder.DirectoryName is null)
|
||||
continue;
|
||||
}
|
||||
if (nameWithoutExtensionIsIdFormat)
|
||||
continue;
|
||||
@ -181,7 +202,8 @@ public class Rename
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!int.TryParse(Path.GetFileName(fileHolder.DirectoryName)[..4], out int year))
|
||||
fileName = Path.GetFileName(fileHolder.DirectoryName);
|
||||
if (fileName.Length < 4 || !int.TryParse(fileName[..4], out int year))
|
||||
year = minimumDateTime.Value.Year;
|
||||
if (_Configuration.IgnoreExtensions.Contains(fileHolder.ExtensionLowered))
|
||||
continue;
|
||||
@ -197,6 +219,9 @@ public class Rename
|
||||
checkFile = Path.Combine(fileHolder.DirectoryName, $"{dateTime.Value:yyyy-MM-dd}.{dateTime.Value.Ticks}.{fileHolder.Length}{checkFileExtension}");
|
||||
if (checkFile == fileHolder.FullName)
|
||||
continue;
|
||||
if (distinct.Contains(checkFile))
|
||||
continue;
|
||||
distinct.Add(checkFile);
|
||||
results.Add(new(fileHolder, checkFile));
|
||||
continue;
|
||||
}
|
||||
@ -212,6 +237,9 @@ public class Rename
|
||||
if (File.Exists(checkFile))
|
||||
continue;
|
||||
}
|
||||
if (distinct.Contains(checkFile))
|
||||
continue;
|
||||
distinct.Add(checkFile);
|
||||
results.Add(new(fileHolder, checkFile));
|
||||
}
|
||||
return results;
|
||||
@ -347,7 +375,9 @@ public class Rename
|
||||
foreach ((FileHolder fileHolder, string to) in verifiedToDoCollection)
|
||||
{
|
||||
results.Add(fileHolder.NameWithoutExtension);
|
||||
File.Move(fileHolder.FullName, to);
|
||||
try
|
||||
{ File.Move(fileHolder.FullName, to); }
|
||||
catch (Exception) { }
|
||||
}
|
||||
log.Information("Done Moving");
|
||||
}
|
||||
@ -359,9 +389,7 @@ public class Rename
|
||||
List<string> results = new();
|
||||
string[] files;
|
||||
string message;
|
||||
int distinctCount;
|
||||
ProgressBar progressBar;
|
||||
List<string> distinctCollection = new();
|
||||
List<(FileHolder, string)> toDoCollection;
|
||||
List<(FileHolder, string)> verifiedToDoCollection;
|
||||
List<string> allFiles = GetAllFiles(matchNginxCollection);
|
||||
@ -374,20 +402,10 @@ public class Rename
|
||||
progressBar = new(files.Length, message, options);
|
||||
if (!files.Any())
|
||||
continue;
|
||||
distinctCollection.Clear();
|
||||
if (!_AppSettings.RenameUndo)
|
||||
toDoCollection = GetToDoCollection(progressBar, files);
|
||||
else
|
||||
toDoCollection = GetRenameUndoToDoCollection(progressBar, files);
|
||||
foreach ((FileHolder fileHolder, string to) in toDoCollection)
|
||||
{
|
||||
if (distinctCollection.Contains(to))
|
||||
continue;
|
||||
distinctCollection.Add(to);
|
||||
}
|
||||
distinctCount = distinctCollection.Count;
|
||||
if (toDoCollection.Count != distinctCount)
|
||||
continue;
|
||||
verifiedToDoCollection = new();
|
||||
foreach ((FileHolder fileHolder, string to) in toDoCollection)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user