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