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