#1 2020-01-19 01:06

Andrew-HOD
Member
Registered: 2020-01-08
Posts: 7

Rename with EXIF Date or Modified Date

Hello,

I am writing to see if there is a way to use EXIF Date if exists otherwise Modified Date

The Pascal Script "Date and Time" works well for Modified Date.
The Insert, Insert Meta Tag works well for EXIF Date etc.

I cannot figure/find a way to use the EXIF Date in the Pascal script if it exists, which is what I assume needs to be done.

I then use
The Pascal Script for Serialize Duplicates

Thank you,

Offline

#2 2020-01-20 13:29

Stefan
Moderator
From: Germany, EU
Registered: 2007-10-23
Posts: 1,161

Re: Rename with EXIF Date or Modified Date

About which script do you talking about? (link?)


Normally we write something like: "IF Exif exists THEN use that".
So we could alter that as like :    "IF Exif exists THEN use that, ELSE use FileTimeModified(FileName)"


Read the  *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)

Offline

#3 2020-01-21 02:48

Andrew-HOD
Member
Registered: 2020-01-08
Posts: 7

Re: Rename with EXIF Date or Modified Date

Hello,

I am using the built in Pascal script "Date and Time" slightly modified for format:

var
  DateTime: TDateTime;

begin
  DateTime := FileTimeModified(FilePath);
  FileName := WideExtractBaseName(FileName) +
    FormatDateTime('yyyy-mm-dd hhmm_ss', DateTime) +
    WideExtractFileExt(FileName);
end.

Offline

#4 2020-01-21 09:57

Stefan
Moderator
From: Germany, EU
Registered: 2007-10-23
Posts: 1,161

Re: Rename with EXIF Date or Modified Date

Ohh, I think now I understood.

Andrew-HOD wrote:

I cannot figure/find a way to use the EXIF Date in the Pascal script ...




See
> https://www.den4b.com/wiki/ReNamer
> https://www.den4b.com/wiki/ReNamer:Scripts   
> 3rd party libraries    > Extract EXIF/IPTC/XMP tags from any images


>> and there f.ex. > http://www.den4b.com/forum/viewtopic.php?id=407

    if Length(DateEXIF) > 0 then
      FileName := DateEXIF[0] + '-' + DateEXIF[1] + '-' + DateEXIF[2] + ' ' +
                  DateEXIF[3] + '.' + DateEXIF[4] + '.' + DateEXIF[5] +
                  WideExtractFileExt(FileName);
  end;
end.

- - -


For your issue, try to change

end;
end.

to

end
	ELSE 
		begin
			showmessage('no exif info, use FileTimeModified');
		end;
end.




- - -



As far as I understand your issue, I can imagine smtg like this will help you:


IF there are EXIF information to extract, use that information
to insert the date into the filename, ELSE use the files Modified Date instead:



{den4b
 http://www.den4b.com/forum/viewtopic.php?id=407
Insert EXIF/IPTC/XMP tags from any images 
Here changed to add an ELSE cause}

const
  EXIV = '"exiv2.exe"';
  TAG = 'Image timestamp\s*\:\s*(.*?)[\r\n]';

var
  Command, Output: String;
  Matches, DateEXIF: TStringsArray;
  DateTime: TDateTime;

begin
	Command := EXIV+' "'+FilePath+'"';
	if ExecConsoleApp(Command, Output) = 0 then
		begin
			Matches := SubMatchesRegEx(Output, TAG, False);
			DateEXIF := SubMatchesRegEx(Matches[0], '(.+)\:(.+)\:(.+)\ (.+)\:(.+)\:(.+)', False);
			if Length(DateEXIF) > 0 then
			FileName := DateEXIF[0] + '-' + DateEXIF[1] + '-' + DateEXIF[2] + ' ' +
					DateEXIF[3] + '.' + DateEXIF[4] + '.' + DateEXIF[5] +
					WideExtractFileExt(FileName);
		end
	ELSE 
		begin
			//showmessage('no exif');
			DateTime := FileTimeModified(FilePath);
			FileName := WideExtractBaseName(FileName) + '_' + 
					FormatDateTime('yyyy-mm-dd hhmm_ss', DateTime) +
					WideExtractFileExt(FileName);
		end;
end.


Some may want to alter the "FileName :=" order of parts.



HTH? . . . or any more questions?


Read the  *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)

Offline

#5 2020-01-29 07:51

Andrew-HOD
Member
Registered: 2020-01-08
Posts: 7

Re: Rename with EXIF Date or Modified Date

Hello, that works very well.  It seems I may have some files that have Exif data that is blank, but I am going to see if I can play with it and see if I can make this work a little better for me, I may post another question, but when I have more time I will try.  Thank you.

Offline

#6 2020-01-29 09:42

Stefan
Moderator
From: Germany, EU
Registered: 2007-10-23
Posts: 1,161

Re: Rename with EXIF Date or Modified Date

Andrew-HOD wrote:

It seems I may have some files that have Exif data that is blank,

What is the problem with such files? What do they show?
Do you say there is smtg in "DateEXIF" but white spaces only?


Maybe try to add:
showmessage('exif 1: __>' + Matches + '<__');
showmessage('exif 2: __>' + DateEXIF+ '<__');


(test that only on a few files!)






 


Read the  *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)

Offline

#7 2020-03-01 08:22

Andrew-HOD
Member
Registered: 2020-01-08
Posts: 7

Re: Rename with EXIF Date or Modified Date

Hello, I am writing to say I believe the proposed solution #4 worked correctly and well for everything.  Great job and thank you.

Offline

#8 2020-03-02 10:04

Stefan
Moderator
From: Germany, EU
Registered: 2007-10-23
Posts: 1,161

Re: Rename with EXIF Date or Modified Date

Thank you for the feedback, Andrew.




 


Read the  *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)

Offline

Board footer

Powered by FluxBB