Rename files to padded number string
This commit is contained in:
@ -45,6 +45,7 @@
|
||||
<PackageReference Include="Serilog" Version="2.12.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Metadata\Metadata.csproj" />
|
||||
<ProjectReference Include="..\Property\Property.csproj" />
|
||||
<ProjectReference Include="..\Shared\View-by-Distance.Shared.csproj" />
|
||||
</ItemGroup>
|
||||
|
@ -2,6 +2,8 @@
|
||||
using Phares.Shared;
|
||||
using Serilog;
|
||||
using ShellProgressBar;
|
||||
using System.Text;
|
||||
using View_by_Distance.Metadata.Models;
|
||||
using View_by_Distance.Set.Created.Date.Models;
|
||||
using View_by_Distance.Shared.Models;
|
||||
using View_by_Distance.Shared.Models.Methods;
|
||||
@ -11,6 +13,8 @@ namespace View_by_Distance.Set.Created.Date;
|
||||
public class SetCreatedDate
|
||||
{
|
||||
|
||||
private record Record(FileHolder FileHolder, bool OriginalSet, DateTime DateTime);
|
||||
|
||||
private readonly AppSettings _AppSettings;
|
||||
private readonly string _WorkingDirectory;
|
||||
private readonly Configuration _Configuration;
|
||||
@ -61,52 +65,76 @@ public class SetCreatedDate
|
||||
{ }
|
||||
}
|
||||
|
||||
private List<(FileHolder, DateTime)> GetToDoCollection(ProgressBar progressBar, List<string[]> filesCollection)
|
||||
private List<Record> GetRecords(ProgressBar progressBar, ASCIIEncoding asciiEncoding, B_Metadata metadata, string[] files)
|
||||
{
|
||||
List<(FileHolder, DateTime)> results = new();
|
||||
List<Record> results = new();
|
||||
int? id;
|
||||
string? message;
|
||||
DateTime? dateTime;
|
||||
DateTime[] dateTimes;
|
||||
FileHolder fileHolder;
|
||||
DateTime?[] dateTimes;
|
||||
bool isIgnoreExtension;
|
||||
DateTime? dateTimeOriginal;
|
||||
bool isValidImageFormatExtension;
|
||||
foreach (string file in files)
|
||||
{
|
||||
progressBar.Tick();
|
||||
fileHolder = new(file);
|
||||
if (fileHolder.ExtensionLowered == ".id" || fileHolder.ExtensionLowered == ".lsv" || fileHolder.DirectoryName is null)
|
||||
continue;
|
||||
if (_PropertyConfiguration.IgnoreExtensions.Contains(fileHolder.ExtensionLowered))
|
||||
continue;
|
||||
isValidImageFormatExtension = _PropertyConfiguration.ValidImageFormatExtensions.Contains(fileHolder.ExtensionLowered);
|
||||
isIgnoreExtension = isValidImageFormatExtension && _PropertyConfiguration.IgnoreExtensions.Contains(fileHolder.ExtensionLowered);
|
||||
if (isIgnoreExtension || !isValidImageFormatExtension)
|
||||
continue;
|
||||
(dateTimeOriginal, dateTimes, id, message) = Property.Models.Stateless.IProperty.Get(_PropertyConfiguration.PopulatePropertyId, metadata, fileHolder, isIgnoreExtension, isValidImageFormatExtension, asciiEncoding);
|
||||
if (dateTimeOriginal is null)
|
||||
results.Add(new(fileHolder, false, dateTimes.Min()));
|
||||
else
|
||||
results.Add(new(fileHolder, true, dateTimeOriginal.Value));
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
private List<Record> GetToDoCollection(ProgressBar progressBar, List<string[]> filesCollection)
|
||||
{
|
||||
List<Record> results = new();
|
||||
int minutes;
|
||||
Record[] records;
|
||||
List<Record> unordered;
|
||||
ASCIIEncoding asciiEncoding = new();
|
||||
B_Metadata metadata = new(_PropertyConfiguration);
|
||||
List<Record[]> collections = new();
|
||||
foreach (string[] files in filesCollection)
|
||||
{
|
||||
foreach (string file in files)
|
||||
minutes = 0;
|
||||
unordered = GetRecords(progressBar, asciiEncoding, metadata, files);
|
||||
records = (from l in unordered orderby l.DateTime, l.FileHolder.Name.Length, l.FileHolder.Name select l).ToArray();
|
||||
foreach (Record record in records)
|
||||
{
|
||||
progressBar.Tick();
|
||||
fileHolder = new(file);
|
||||
if (fileHolder.ExtensionLowered == ".id" || fileHolder.ExtensionLowered == ".lsv" || fileHolder.DirectoryName is null)
|
||||
if (record.DateTime == record.FileHolder.CreationTime)
|
||||
continue;
|
||||
if (_PropertyConfiguration.IgnoreExtensions.Contains(fileHolder.ExtensionLowered))
|
||||
continue;
|
||||
isValidImageFormatExtension = _PropertyConfiguration.ValidImageFormatExtensions.Contains(fileHolder.ExtensionLowered);
|
||||
isIgnoreExtension = isValidImageFormatExtension && _PropertyConfiguration.IgnoreExtensions.Contains(fileHolder.ExtensionLowered);
|
||||
if (isIgnoreExtension || !isValidImageFormatExtension)
|
||||
continue;
|
||||
(dateTimeOriginal, dateTimes, id, message) = Shared.Models.Stateless.Methods.IProperty.Get(fileHolder, isIgnoreExtension, isValidImageFormatExtension, _PropertyConfiguration.PopulatePropertyId);
|
||||
dateTime = dateTimeOriginal is not null ? dateTimeOriginal : dateTime = dateTimes.Min();
|
||||
if (dateTime is null)
|
||||
continue;
|
||||
if (dateTime.Value == fileHolder.CreationTime)
|
||||
continue;
|
||||
results.Add((fileHolder, dateTime.Value));
|
||||
if (record.OriginalSet)
|
||||
results.Add(new(record.FileHolder, record.OriginalSet, record.DateTime));
|
||||
else
|
||||
{
|
||||
minutes += 1;
|
||||
results.Add(new(record.FileHolder, record.OriginalSet, record.DateTime.AddMinutes(minutes)));
|
||||
}
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
private static List<string> SetCreatedDateForeach(ProgressBar progressBar, List<(FileHolder, DateTime)> toDoCollection)
|
||||
private static List<string> SetCreatedDateForeach(ProgressBar progressBar, List<Record> toDoCollection)
|
||||
{
|
||||
List<string> results = new();
|
||||
foreach ((FileHolder fileHolder, DateTime dateTime) in toDoCollection)
|
||||
foreach (Record record in toDoCollection)
|
||||
{
|
||||
progressBar.Tick();
|
||||
results.Add(fileHolder.NameWithoutExtension);
|
||||
results.Add(record.FileHolder.NameWithoutExtension);
|
||||
try
|
||||
{ File.SetCreationTime(fileHolder.FullName, dateTime); }
|
||||
{ File.SetCreationTime(record.FileHolder.FullName, record.DateTime); }
|
||||
catch (Exception) { }
|
||||
}
|
||||
return results;
|
||||
@ -124,7 +152,7 @@ public class SetCreatedDate
|
||||
int count = filesCollection.Select(l => l.Length).Sum();
|
||||
ProgressBarOptions options = new() { ProgressCharacter = '─', ProgressBarOnBottom = true, DisableBottomPercentage = true };
|
||||
progressBar = new(count, message, options);
|
||||
List<(FileHolder, DateTime)> toDoCollection = GetToDoCollection(progressBar, filesCollection);
|
||||
List<Record> toDoCollection = GetToDoCollection(progressBar, filesCollection);
|
||||
progressBar.Dispose();
|
||||
log.Information($"Ready to set created date {toDoCollection.Count} file(s)?");
|
||||
for (int y = 0; y < int.MaxValue; y++)
|
||||
|
@ -68,7 +68,6 @@
|
||||
"ResultContent": "()",
|
||||
"ResultSingleton": "{}",
|
||||
"RootDirectory": "D:/Images",
|
||||
"WriteBitmapDataBytes": false,
|
||||
"IgnoreExtensions": [
|
||||
".gif",
|
||||
".GIF",
|
||||
@ -92,36 +91,6 @@
|
||||
".TIFF",
|
||||
".tif",
|
||||
".TIF"
|
||||
],
|
||||
"ValidMetadataExtensions": [
|
||||
".3gp",
|
||||
".3GP",
|
||||
".avi",
|
||||
".AVI",
|
||||
".bmp",
|
||||
".BMP",
|
||||
".gif",
|
||||
".GIF",
|
||||
".ico",
|
||||
".ICO",
|
||||
".jpeg",
|
||||
".JPEG",
|
||||
".jpg",
|
||||
".JPG",
|
||||
".m4v",
|
||||
".M4V",
|
||||
".mov",
|
||||
".MOV",
|
||||
".mp4",
|
||||
".MP4",
|
||||
".mta",
|
||||
".MTA",
|
||||
".png",
|
||||
".PNG",
|
||||
".tiff",
|
||||
".TIFF",
|
||||
".tif",
|
||||
".TIF"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user