CopyTo
This commit is contained in:
parent
c5986b5cba
commit
9dd218a5f2
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"CompareRootDirectory": "D:/7) Question/- - - Images",
|
"CompareRootDirectory": "D:/7) Question/- - - Images - 2023-01-12/fa60aa45ebb55fe3ee0ce4da8a64e40611e7d5ce",
|
||||||
"Logging": {
|
"Logging": {
|
||||||
"LogLevel": {
|
"LogLevel": {
|
||||||
"Log4netProvider": "Debug"
|
"Log4netProvider": "Debug"
|
||||||
@ -15,9 +15,10 @@
|
|||||||
"Configuration": {
|
"Configuration": {
|
||||||
"xRootDirectory": "D:/2) Images B/Corrupt",
|
"xRootDirectory": "D:/2) Images B/Corrupt",
|
||||||
"xxRootDirectory": "D:/2) Images B/Not-Copy-Copy-45f4401",
|
"xxRootDirectory": "D:/2) Images B/Not-Copy-Copy-45f4401",
|
||||||
"RootDirectory": "D:/1) Images A/Images-45f4401",
|
"xxxRootDirectory": "D:/1) Images A/Images-45f4401",
|
||||||
"xxxxRootDirectory": "E:/3) Videos A/Device Videos 2_0_0_3 - Current",
|
"xxxxRootDirectory": "E:/3) Videos A/Device Videos 2_0_0_3 - Current",
|
||||||
"xxxxxRootDirectory": "E:/4) Videos B/Device Videos 2_0_0_3 - Current - Ignore",
|
"xxxxxRootDirectory": "E:/4) Videos B/Device Videos 2_0_0_3 - Current - Ignore",
|
||||||
|
"RootDirectory": "C:/1) Images A/Images-45f4401",
|
||||||
"VerifyToSeason": []
|
"VerifyToSeason": []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,14 +7,16 @@ public class AppSettings
|
|||||||
{
|
{
|
||||||
|
|
||||||
public string Company { init; get; }
|
public string Company { init; get; }
|
||||||
|
public string CopyTo { init; get; }
|
||||||
public string ComparePathsFile { init; get; }
|
public string ComparePathsFile { init; get; }
|
||||||
public int MaxDegreeOfParallelism { init; get; }
|
public int MaxDegreeOfParallelism { init; get; }
|
||||||
public string WorkingDirectoryName { init; get; }
|
public string WorkingDirectoryName { init; get; }
|
||||||
|
|
||||||
[JsonConstructor]
|
[JsonConstructor]
|
||||||
public AppSettings(string company, string comparePathsFile, int maxDegreeOfParallelism, string workingDirectoryName)
|
public AppSettings(string company, string copyTo, string comparePathsFile, int maxDegreeOfParallelism, string workingDirectoryName)
|
||||||
{
|
{
|
||||||
Company = company;
|
Company = company;
|
||||||
|
CopyTo = copyTo;
|
||||||
ComparePathsFile = comparePathsFile;
|
ComparePathsFile = comparePathsFile;
|
||||||
MaxDegreeOfParallelism = maxDegreeOfParallelism;
|
MaxDegreeOfParallelism = maxDegreeOfParallelism;
|
||||||
WorkingDirectoryName = workingDirectoryName;
|
WorkingDirectoryName = workingDirectoryName;
|
||||||
|
@ -9,6 +9,7 @@ public class AppSettings
|
|||||||
#nullable disable
|
#nullable disable
|
||||||
|
|
||||||
public string Company { get; set; }
|
public string Company { get; set; }
|
||||||
|
public string CopyTo { get; set; }
|
||||||
public string ComparePathsFile { get; set; }
|
public string ComparePathsFile { get; set; }
|
||||||
public int? MaxDegreeOfParallelism { get; set; }
|
public int? MaxDegreeOfParallelism { get; set; }
|
||||||
public string WorkingDirectoryName { get; set; }
|
public string WorkingDirectoryName { get; set; }
|
||||||
@ -28,6 +29,7 @@ public class AppSettings
|
|||||||
throw new NullReferenceException(nameof(appSettings.MaxDegreeOfParallelism));
|
throw new NullReferenceException(nameof(appSettings.MaxDegreeOfParallelism));
|
||||||
result = new(
|
result = new(
|
||||||
appSettings.Company,
|
appSettings.Company,
|
||||||
|
appSettings.CopyTo,
|
||||||
appSettings.ComparePathsFile,
|
appSettings.ComparePathsFile,
|
||||||
appSettings.MaxDegreeOfParallelism.Value,
|
appSettings.MaxDegreeOfParallelism.Value,
|
||||||
appSettings.WorkingDirectoryName
|
appSettings.WorkingDirectoryName
|
||||||
|
@ -92,7 +92,7 @@ public class Rename
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private (List<(FileHolder, string)>, int) RenameFilesInDirectory(ProgressBar progressBar, string[] files)
|
private List<(FileHolder, string)> GetRenameCollection(ProgressBar progressBar, string[] files)
|
||||||
{
|
{
|
||||||
List<(FileHolder, string)> results = new();
|
List<(FileHolder, string)> results = new();
|
||||||
int? id;
|
int? id;
|
||||||
@ -109,27 +109,25 @@ public class Rename
|
|||||||
const string jpeg = ".jpeg";
|
const string jpeg = ".jpeg";
|
||||||
bool isValidImageFormatExtension;
|
bool isValidImageFormatExtension;
|
||||||
bool nameWithoutExtensionIsIdFormat;
|
bool nameWithoutExtensionIsIdFormat;
|
||||||
List<string> distinctCollection = new();
|
|
||||||
IReadOnlyList<MetadataExtractor.Directory> directories;
|
IReadOnlyList<MetadataExtractor.Directory> directories;
|
||||||
foreach (string file in files)
|
foreach (string file in files)
|
||||||
{
|
{
|
||||||
progressBar.Tick();
|
progressBar.Tick();
|
||||||
|
fileHolder = new(file);
|
||||||
// else if (file.EndsWith(".del") && !file.Contains(".jpg"))
|
// else if (file.EndsWith(".del") && !file.Contains(".jpg"))
|
||||||
// {
|
// {
|
||||||
// checkFile = string.Concat(file[..^4], ".jpg");
|
// checkFile = string.Concat(file[..^4], ".jpg");
|
||||||
// if (File.Exists(checkFile))
|
// if (File.Exists(checkFile))
|
||||||
// continue;
|
// continue;
|
||||||
// File.Move(file, checkFile);
|
// results.Add(new(fileHolder, checkFile));
|
||||||
// continue;
|
// continue;
|
||||||
// }
|
// }
|
||||||
if (!file.EndsWith(".jpg.del"))
|
if (file.EndsWith(".jpg.del"))
|
||||||
fileHolder = new(file);
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
checkFile = file[..^4];
|
checkFile = file[..^4];
|
||||||
if (File.Exists(checkFile))
|
if (File.Exists(checkFile))
|
||||||
continue;
|
continue;
|
||||||
File.Move(file, checkFile);
|
results.Add(new(fileHolder, checkFile));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (fileHolder.ExtensionLowered == ".id" || fileHolder.DirectoryName is null)
|
if (fileHolder.ExtensionLowered == ".id" || fileHolder.DirectoryName is null)
|
||||||
@ -148,12 +146,12 @@ 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;
|
||||||
File.Move($"{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;
|
||||||
File.Move(fileHolder.FullName, checkFile);
|
results.Add(new(fileHolder, checkFile));
|
||||||
}
|
}
|
||||||
if (nameWithoutExtensionIsIdFormat)
|
if (nameWithoutExtensionIsIdFormat)
|
||||||
continue;
|
continue;
|
||||||
@ -178,15 +176,12 @@ public class Rename
|
|||||||
dateTime = Metadata.Models.Stateless.Methods.IMetadata.GetMinimumDateTime(dateTimes, year, directories);
|
dateTime = Metadata.Models.Stateless.Methods.IMetadata.GetMinimumDateTime(dateTimes, year, directories);
|
||||||
timeSpan = new TimeSpan(int.MaxValue);
|
timeSpan = new TimeSpan(int.MaxValue);
|
||||||
}
|
}
|
||||||
if (dateTime is not null && timeSpan.TotalMinutes > 2)
|
if (dateTime is not null && string.IsNullOrEmpty(_AppSettings.CopyTo) && timeSpan.TotalMinutes > 2)
|
||||||
{
|
{
|
||||||
checkFileExtension = fileHolder.ExtensionLowered == jpeg ? jpg : fileHolder.ExtensionLowered;
|
checkFileExtension = fileHolder.ExtensionLowered == jpeg ? jpg : fileHolder.ExtensionLowered;
|
||||||
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 (distinctCollection.Contains(checkFile))
|
|
||||||
continue;
|
|
||||||
distinctCollection.Add(checkFile);
|
|
||||||
results.Add(new(fileHolder, checkFile));
|
results.Add(new(fileHolder, checkFile));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -202,12 +197,9 @@ public class Rename
|
|||||||
if (File.Exists(checkFile))
|
if (File.Exists(checkFile))
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (distinctCollection.Contains(checkFile))
|
|
||||||
continue;
|
|
||||||
distinctCollection.Add(checkFile);
|
|
||||||
results.Add(new(fileHolder, checkFile));
|
results.Add(new(fileHolder, checkFile));
|
||||||
}
|
}
|
||||||
return new(results, distinctCollection.Count);
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void Rename2000(MatchNginx[] matchNginxCollection)
|
private static void Rename2000(MatchNginx[] matchNginxCollection)
|
||||||
@ -269,6 +261,34 @@ public class Rename
|
|||||||
return allFiles;
|
return allFiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void CreateDirectories(List<string> directories)
|
||||||
|
{
|
||||||
|
foreach (string directory in directories)
|
||||||
|
{
|
||||||
|
if (Directory.Exists(directory))
|
||||||
|
continue;
|
||||||
|
_ = Directory.CreateDirectory(directory);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CopyInstead(List<(FileHolder, string)> renameCollection)
|
||||||
|
{
|
||||||
|
string? directory;
|
||||||
|
List<string> distinctDirectories = new();
|
||||||
|
foreach ((FileHolder fileHolder, string to) in renameCollection)
|
||||||
|
{
|
||||||
|
directory = Path.GetDirectoryName($"{_AppSettings.CopyTo}{to[1..]}");
|
||||||
|
if (directory is null)
|
||||||
|
continue;
|
||||||
|
if (distinctDirectories.Contains(directory))
|
||||||
|
continue;
|
||||||
|
distinctDirectories.Add(directory);
|
||||||
|
}
|
||||||
|
CreateDirectories(distinctDirectories);
|
||||||
|
foreach ((FileHolder fileHolder, string to) in renameCollection)
|
||||||
|
File.Copy(fileHolder.FullName, $"{_AppSettings.CopyTo}{to[1..]}");
|
||||||
|
}
|
||||||
|
|
||||||
private List<string> RenameFilesInDirectories(ProgressBarOptions options, MatchNginx[] matchNginxCollection)
|
private List<string> RenameFilesInDirectories(ProgressBarOptions options, MatchNginx[] matchNginxCollection)
|
||||||
{
|
{
|
||||||
List<string> results = new();
|
List<string> results = new();
|
||||||
@ -276,6 +296,7 @@ public class Rename
|
|||||||
string message;
|
string message;
|
||||||
int distinctCount;
|
int distinctCount;
|
||||||
ProgressBar progressBar;
|
ProgressBar progressBar;
|
||||||
|
List<string> distinctCollection = new();
|
||||||
List<(FileHolder, string)> renameCollection;
|
List<(FileHolder, string)> renameCollection;
|
||||||
List<string> allFiles = GetAllFiles(matchNginxCollection);
|
List<string> allFiles = GetAllFiles(matchNginxCollection);
|
||||||
for (int i = 1; i < 3; i++)
|
for (int i = 1; i < 3; i++)
|
||||||
@ -285,17 +306,30 @@ public class Rename
|
|||||||
progressBar = new(files.Length, message, options);
|
progressBar = new(files.Length, message, options);
|
||||||
if (!files.Any())
|
if (!files.Any())
|
||||||
continue;
|
continue;
|
||||||
(renameCollection, distinctCount) = RenameFilesInDirectory(progressBar, files);
|
distinctCollection.Clear();
|
||||||
|
renameCollection = GetRenameCollection(progressBar, files);
|
||||||
|
foreach ((FileHolder fileHolder, string to) in renameCollection)
|
||||||
|
{
|
||||||
|
if (distinctCollection.Contains(to))
|
||||||
|
continue;
|
||||||
|
distinctCollection.Add(to);
|
||||||
|
}
|
||||||
|
distinctCount = distinctCollection.Count;
|
||||||
|
if (renameCollection.Count != distinctCount)
|
||||||
|
continue;
|
||||||
|
if (!string.IsNullOrEmpty(_AppSettings.CopyTo))
|
||||||
|
CopyInstead(renameCollection);
|
||||||
|
else
|
||||||
|
{
|
||||||
foreach ((FileHolder fileHolder, string to) in renameCollection)
|
foreach ((FileHolder fileHolder, string to) in renameCollection)
|
||||||
{
|
{
|
||||||
results.Add(fileHolder.NameWithoutExtension);
|
results.Add(fileHolder.NameWithoutExtension);
|
||||||
if (renameCollection.Count != distinctCount)
|
|
||||||
continue;
|
|
||||||
if (File.Exists(to))
|
if (File.Exists(to))
|
||||||
continue;
|
continue;
|
||||||
File.Move(fileHolder.FullName, to);
|
File.Move(fileHolder.FullName, to);
|
||||||
File.WriteAllText($"{to}.id", $"{to}{Environment.NewLine}{fileHolder.FullName}");
|
File.WriteAllText($"{to}.id", $"{to}{Environment.NewLine}{fileHolder.FullName}");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
progressBar.Dispose();
|
progressBar.Dispose();
|
||||||
}
|
}
|
||||||
return results;
|
return results;
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"ComparePathsFile": "C:/Users/mikep/AppData/Local/PharesApps/Drag-Drop-Explorer/2023_02/638089737585839769.json",
|
"ComparePathsFile": "C:/Users/mikep/AppData/Local/PharesApps/Drag-Drop-Explorer/2023_03/638095753937985087.json",
|
||||||
|
"CopyTo": "C",
|
||||||
"Logging": {
|
"Logging": {
|
||||||
"LogLevel": {
|
"LogLevel": {
|
||||||
"Log4netProvider": "Debug"
|
"Log4netProvider": "Debug"
|
||||||
|
@ -107,6 +107,7 @@ internal abstract class Property
|
|||||||
new string[] { string.Empty, "yyyyMMdd_", ticksExample },
|
new string[] { string.Empty, "yyyyMMdd_", ticksExample },
|
||||||
new string[] { string.Empty, "yyyy-MM-dd_", ticksExample },
|
new string[] { string.Empty, "yyyy-MM-dd_", ticksExample },
|
||||||
new string[] { string.Empty, "yyyy-MM-dd.", ticksExample },
|
new string[] { string.Empty, "yyyy-MM-dd.", ticksExample },
|
||||||
|
new string[] { string.Empty, "yyyy-MM-dd.", $"{ticksExample}.{fileHolder.Length}" },
|
||||||
new string[] { string.Empty, "yyyy-MM-dd HH.mm.ss", string.Empty },
|
new string[] { string.Empty, "yyyy-MM-dd HH.mm.ss", string.Empty },
|
||||||
new string[] { string.Empty, "yyyyMMdd_HHmmss", "_LLS" },
|
new string[] { string.Empty, "yyyyMMdd_HHmmss", "_LLS" },
|
||||||
new string[] { string.Empty, "yyyyMMdd_HHmmss", "_HDR" },
|
new string[] { string.Empty, "yyyyMMdd_HHmmss", "_HDR" },
|
||||||
|
Loading…
x
Reference in New Issue
Block a user