Copy with duplicates
This commit is contained in:
parent
3092cd5b9e
commit
d1c194197d
@ -84,6 +84,8 @@ public class CopyDistinct
|
||||
{
|
||||
List<(FileHolder, string)> results = new();
|
||||
string checkFile;
|
||||
string directory;
|
||||
FileInfo fileInfo;
|
||||
int directoryIndex;
|
||||
FileHolder fileHolder;
|
||||
List<string> distinct = new();
|
||||
@ -104,19 +106,67 @@ public class CopyDistinct
|
||||
continue;
|
||||
}
|
||||
(_, directoryIndex) = Shared.Models.Stateless.Methods.IPath.GetDirectoryNameAndIndex(_PropertyConfiguration.ResultAllInOneSubdirectoryLength, fileHolder.NameWithoutExtension);
|
||||
checkFile = Path.Combine(_FileGroups[_PropertyConfiguration.ResultContent][directoryIndex], fileHolder.Name);
|
||||
directory = _FileGroups[_PropertyConfiguration.ResultContent][directoryIndex];
|
||||
checkFile = Path.Combine(directory, $"{fileHolder.NameWithoutExtension}{fileHolder.ExtensionLowered}");
|
||||
if (distinct.Contains(checkFile))
|
||||
{
|
||||
for (int i = 1; i < int.MaxValue; i++)
|
||||
{
|
||||
fileInfo = new(checkFile);
|
||||
if (fileHolder.Length != fileInfo.Length || fileHolder.LastWriteTime != fileInfo.LastWriteTime)
|
||||
checkFile = Path.Combine(directory, $"{fileHolder.NameWithoutExtension}.{i}why{fileHolder.ExtensionLowered}");
|
||||
else
|
||||
checkFile = Path.Combine(directory, $"{fileHolder.NameWithoutExtension}.{i}dup{fileHolder.ExtensionLowered}");
|
||||
if (distinct.Contains(checkFile))
|
||||
continue;
|
||||
distinct.Add(checkFile);
|
||||
results.Add(new(fileHolder, checkFile));
|
||||
break;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
distinct.Add(checkFile);
|
||||
results.Add(new(fileHolder, checkFile));
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
private static List<string> Copy(ILogger log, List<(FileHolder, string)> toDoCollection)
|
||||
private static List<string> Copy(ProgressBar progressBar, List<(FileHolder, string)> toDoCollection)
|
||||
{
|
||||
List<string> results = new();
|
||||
FileInfo fileInfo;
|
||||
foreach ((FileHolder fileHolder, string to) in toDoCollection)
|
||||
{
|
||||
progressBar.Tick();
|
||||
fileInfo = new(to);
|
||||
if (fileInfo.Exists)
|
||||
{
|
||||
if (fileHolder.Length != fileInfo.Length || fileHolder.LastWriteTime != fileInfo.LastWriteTime)
|
||||
fileInfo.Delete();
|
||||
continue;
|
||||
}
|
||||
results.Add(fileHolder.NameWithoutExtension);
|
||||
try
|
||||
{ File.Copy(fileHolder.FullName, to); }
|
||||
catch (Exception) { }
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
private List<string> CopyDistinctFilesInDirectories(ILogger log)
|
||||
{
|
||||
List<string> results = new();
|
||||
ProgressBar progressBar;
|
||||
ConsoleKey? consoleKey = null;
|
||||
const string fileSearchFilter = "*";
|
||||
string message = nameof(CopyDistinct);
|
||||
const string directorySearchFilter = "*";
|
||||
List<string[]> filesCollection = Shared.Models.Stateless.Methods.IDirectory.GetFilesCollection(_PropertyConfiguration.RootDirectory, directorySearchFilter, fileSearchFilter);
|
||||
(_, List<string> allFiles) = Get(filesCollection);
|
||||
ProgressBarOptions options = new() { ProgressCharacter = '─', ProgressBarOnBottom = true, DisableBottomPercentage = true };
|
||||
progressBar = new(allFiles.Count, message, options);
|
||||
List<(FileHolder, string)> toDoCollection = GetToDoCollection(progressBar, allFiles);
|
||||
progressBar.Dispose();
|
||||
log.Information($"Ready to Copy {toDoCollection.Count} file(s)?");
|
||||
for (int y = 0; y < int.MaxValue; y++)
|
||||
{
|
||||
@ -130,34 +180,12 @@ public class CopyDistinct
|
||||
log.Information("Nothing copied!");
|
||||
else
|
||||
{
|
||||
foreach ((FileHolder fileHolder, string to) in toDoCollection)
|
||||
{
|
||||
if (File.Exists(to))
|
||||
continue;
|
||||
results.Add(fileHolder.NameWithoutExtension);
|
||||
try
|
||||
{ File.Copy(fileHolder.FullName, to); }
|
||||
catch (Exception) { }
|
||||
}
|
||||
progressBar = new(allFiles.Count, message, options);
|
||||
results.AddRange(Copy(progressBar, toDoCollection));
|
||||
progressBar.Dispose();
|
||||
log.Information("Done copying");
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
private List<string> CopyDistinctFilesInDirectories(ILogger log)
|
||||
{
|
||||
List<string> results = new();
|
||||
const string fileSearchFilter = "*";
|
||||
string message = nameof(CopyDistinct);
|
||||
const string directorySearchFilter = "*";
|
||||
List<string[]> filesCollection = Shared.Models.Stateless.Methods.IDirectory.GetFilesCollection(_PropertyConfiguration.RootDirectory, directorySearchFilter, fileSearchFilter);
|
||||
(_, List<string> allFiles) = Get(filesCollection);
|
||||
ProgressBarOptions options = new() { ProgressCharacter = '─', ProgressBarOnBottom = true, DisableBottomPercentage = true };
|
||||
ProgressBar progressBar = new(allFiles.Count, message, options);
|
||||
List<(FileHolder, string)> toDoCollection = GetToDoCollection(progressBar, allFiles);
|
||||
progressBar.Dispose();
|
||||
results.AddRange(Copy(log, toDoCollection));
|
||||
return results;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user