first working version
This commit is contained in:
parent
4455254952
commit
eb11d7d2db
@ -17,17 +17,17 @@ namespace PhotoRenamer
|
||||
private readonly string _sourcePath;
|
||||
private readonly string _targetPath;
|
||||
|
||||
public Renamer(IConfigurationRoot configuration)
|
||||
public Renamer(IConfiguration configuration)
|
||||
{
|
||||
_sourcePath = Path.GetFullPath(configuration["Source"]);
|
||||
_targetPath = Path.GetFullPath(configuration["Target"]);
|
||||
Log.Information($"Source path {_sourcePath}");
|
||||
Log.Information($"Target path {_targetPath}");
|
||||
Log.Information($"Source path: {_sourcePath}");
|
||||
Log.Information($"Target path: {_targetPath}");
|
||||
}
|
||||
|
||||
public int Run()
|
||||
{
|
||||
var files = Directory.GetFiles(_sourcePath);
|
||||
var files = Directory.GetFiles(_sourcePath, "*", SearchOption.AllDirectories);
|
||||
var options = new ProgressBarOptions
|
||||
{
|
||||
ForegroundColor = ConsoleColor.Yellow,
|
||||
@ -39,19 +39,26 @@ namespace PhotoRenamer
|
||||
foreach (var file in files)
|
||||
{
|
||||
progressBar.Tick();
|
||||
var directories = ImageMetadataReader.ReadMetadata(file);
|
||||
try
|
||||
{
|
||||
var directories = ImageMetadataReader.ReadMetadata(file);
|
||||
|
||||
var dateTime = GetDateTimeFromExif(directories) ?? GetDateTimeFromMp4(directories);
|
||||
if (dateTime is null) continue;
|
||||
var yearFolder = Path.Combine(_targetPath, dateTime.Value.Year.ToString());
|
||||
var monthFolder = Path.Combine(yearFolder, dateTime.Value.Month.ToString("D2"));
|
||||
var dayFolder = Path.Combine(monthFolder, dateTime.Value.Day.ToString("D2"));
|
||||
if (!Directory.Exists(yearFolder)) Directory.CreateDirectory(yearFolder);
|
||||
if (!Directory.Exists(monthFolder)) Directory.CreateDirectory(monthFolder);
|
||||
if (!Directory.Exists(dayFolder)) Directory.CreateDirectory(dayFolder);
|
||||
var destination = Path.Combine(dayFolder, Path.GetFileName(file));
|
||||
if (File.Exists(destination)) continue;
|
||||
File.Copy(file, destination);
|
||||
var dateTime = GetDateTimeFromExif(directories) ?? GetDateTimeFromMp4(directories);
|
||||
if (dateTime is null) continue;
|
||||
var dayFolder = Path.Combine(
|
||||
_targetPath,
|
||||
dateTime.Value.Year.ToString(),
|
||||
dateTime.Value.Month.ToString("D2"),
|
||||
dateTime.Value.Day.ToString("D2"));
|
||||
if (!Directory.Exists(dayFolder)) Directory.CreateDirectory(dayFolder);
|
||||
var destination = Path.Combine(dayFolder, Path.GetFileName(file));
|
||||
if (File.Exists(destination)) continue;
|
||||
File.Copy(file, destination);
|
||||
}
|
||||
catch (ImageProcessingException)
|
||||
{
|
||||
//silently ignore
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -1,4 +1,4 @@
|
||||
{
|
||||
"Source": "C:\\Test",
|
||||
"Source": "C:\\Users\\Holger\\Nextcloud\\DCIM",
|
||||
"Target": "C:\\Target"
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user