Copy with duplicates
This commit is contained in:
parent
3092cd5b9e
commit
d1c194197d
@ -84,6 +84,8 @@ public class CopyDistinct
|
|||||||
{
|
{
|
||||||
List<(FileHolder, string)> results = new();
|
List<(FileHolder, string)> results = new();
|
||||||
string checkFile;
|
string checkFile;
|
||||||
|
string directory;
|
||||||
|
FileInfo fileInfo;
|
||||||
int directoryIndex;
|
int directoryIndex;
|
||||||
FileHolder fileHolder;
|
FileHolder fileHolder;
|
||||||
List<string> distinct = new();
|
List<string> distinct = new();
|
||||||
@ -104,19 +106,67 @@ public class CopyDistinct
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
(_, directoryIndex) = Shared.Models.Stateless.Methods.IPath.GetDirectoryNameAndIndex(_PropertyConfiguration.ResultAllInOneSubdirectoryLength, fileHolder.NameWithoutExtension);
|
(_, 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))
|
if (distinct.Contains(checkFile))
|
||||||
continue;
|
continue;
|
||||||
distinct.Add(checkFile);
|
distinct.Add(checkFile);
|
||||||
results.Add(new(fileHolder, checkFile));
|
results.Add(new(fileHolder, checkFile));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
distinct.Add(checkFile);
|
||||||
|
results.Add(new(fileHolder, checkFile));
|
||||||
}
|
}
|
||||||
return results;
|
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();
|
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;
|
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)?");
|
log.Information($"Ready to Copy {toDoCollection.Count} file(s)?");
|
||||||
for (int y = 0; y < int.MaxValue; y++)
|
for (int y = 0; y < int.MaxValue; y++)
|
||||||
{
|
{
|
||||||
@ -130,34 +180,12 @@ public class CopyDistinct
|
|||||||
log.Information("Nothing copied!");
|
log.Information("Nothing copied!");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
foreach ((FileHolder fileHolder, string to) in toDoCollection)
|
progressBar = new(allFiles.Count, message, options);
|
||||||
{
|
results.AddRange(Copy(progressBar, toDoCollection));
|
||||||
if (File.Exists(to))
|
progressBar.Dispose();
|
||||||
continue;
|
|
||||||
results.Add(fileHolder.NameWithoutExtension);
|
|
||||||
try
|
|
||||||
{ File.Copy(fileHolder.FullName, to); }
|
|
||||||
catch (Exception) { }
|
|
||||||
}
|
|
||||||
log.Information("Done copying");
|
log.Information("Done copying");
|
||||||
}
|
}
|
||||||
return results;
|
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