EXIF Conditional Rename

Discuss and share scripts and script files...
Post Reply
aimy
Posts: 186
Joined: 26 Feb 2007 15:44

EXIF Conditional Rename

Post by aimy »

Saturday, 6 April 2024 06:41:39 AM
---------------------------------------------------------------------------------------
Hi.

I have an existing script provided by highend, to automatically rename image files based on the file property ie EXIF date & camera model.

It works perfectly nice!

Thanks again to highend for this.

However, at times, there will be a conflicting filenames, due to same EXIF date:
20240406.064703_XYplorer.jpg
20240406.064703_XYplorer.jpg (181.08 KiB) Viewed 305 times
I've already contacted highend privately, but I still cannot figure out on how to do that.

I am thinking of using regex at the end of the stage, but it still didn't work as expected.

Any help?

Attached is the original script and the one that I tried to modify.
XYplorer_EXIF Conditional Rename.xys
(3.4 KiB) Downloaded 12 times
XYplorer_EXIF Conditional Rename_EDITED_v4.xys
(5.31 KiB) Downloaded 9 times
Thank you.

aimy
Posts: 186
Joined: 26 Feb 2007 15:44

Re: EXIF Conditional Rename

Post by aimy »

Any help? :(

Thanks

jupe
Posts: 2809
Joined: 20 Oct 2017 21:14
Location: Win10 22H2 120dpi

Re: EXIF Conditional Rename

Post by jupe »

I didn't look at your edited version, but you haven't said what you want to happen when there are collisions, anyway if you are interested in a crude fix as a starting point, you should be able to just add a line like this

Code: Select all

if (regexmatches($previewNames, "^$pattern$")) { $pattern = regexreplace($pattern, "([^.]+?)$", "<get rs 3 0123456789>.$1"); }
directly before this line: $previewNames = $previewNames . $pattern . "<crlf>";

I'll leave it up to you to escape the string if you feel it necessary. Totally untested aircode.

aimy
Posts: 186
Joined: 26 Feb 2007 15:44

Re: EXIF Conditional Rename

Post by aimy »

jupe wrote: 23 Apr 2024 19:58 I didn't look at your edited version, but you haven't said what you want to happen when there are collisions, anyway if you are interested in a crude fix as a starting point, you should be able to just add a line like this

Code: Select all

if (regexmatches($previewNames, "^$pattern$")) { $pattern = regexreplace($pattern, "([^.]+?)$", "<get rs 3 0123456789>.$1"); }
directly before this line: $previewNames = $previewNames . $pattern . "<crlf>";

I'll leave it up to you to escape the string if you feel it necessary. Totally untested aircode.
wow!!! it works like a charm!!!
20240424.091401_XYplorer.jpg
20240424.091401_XYplorer.jpg (460.4 KiB) Viewed 173 times
Thank you so much jupe!!

I really appreciate it :appl:

But is it possible instead of appending random number at the end to something like this.. _XX sequence number based on the duplicate occurrence.

Code: Select all

20240302.033326¬PGT-N19_01.jpg
20240302.033326¬PGT-N19_02.jpg
20240302.033326¬PGT-N19_03.jpg
20240302.033326¬PGT-N19_04.jpg
---------------------------------------------------------------------------------------
20240302.074541¬PGT-N19_01.jpg
20240302.074541¬PGT-N19_02.jpg
---------------------------------------------------------------------------------------
20240302.080803¬PGT-N19_01.jpg
---------------------------------------------------------------------------------------
20240302.081347¬PGT-N19_01.jpg
Thanks again in advance for your help.

jupe
Posts: 2809
Joined: 20 Oct 2017 21:14
Location: Win10 22H2 120dpi

Re: EXIF Conditional Rename

Post by jupe »

Sure its possible, I was leaving that up to you though. ;)
Anyway, since you asked, something like this should work:

Code: Select all

  $cntCol = gettokenindex(regexreplace($pattern, "(\.[^.]+?)$") . "*",  $previewNames, <crlf>, "iwc");
  if ($cntCol) { $pattern = regexreplace($pattern, "(\.[^.]+?)$", "_" . format($cntCol, "00") . "$1"); }
Replace previous suggestion with these 2 lines instead. Again, it is untested. First collision won't have index, only following, if you want it different, that's up to you to implement, I can explain how though if you ask.

aimy
Posts: 186
Joined: 26 Feb 2007 15:44

Re: EXIF Conditional Rename

Post by aimy »

jupe wrote: 24 Apr 2024 03:48 Sure its possible, I was leaving that up to you though. ;)
Anyway, since you asked, something like this should work:

Code: Select all

  $cntCol = gettokenindex(regexreplace($pattern, "(\.[^.]+?)$") . "*",  $previewNames, <crlf>, "iwc");
  if ($cntCol) { $pattern = regexreplace($pattern, "(\.[^.]+?)$", "_" . format($cntCol, "00") . "$1"); }
Replace previous suggestion with these 2 lines instead. Again, it is untested. First collision won't have index, only following, if you want it different, that's up to you to implement, I can explain how though if you ask.
Thanks again so much!! It really works!! :party:

But sorry.. Is it possible to cater the scenario whereby.. The existing file already exists (previous batch renaming).

So it will come out like this.
20240424.105848_XYplorer.jpg
20240424.105848_XYplorer.jpg (111.8 KiB) Viewed 117 times
Is it possible to rename those automatically with the duplicate extension?

Actually I forgot that I want my filename to be this format actually:
20240302.033326¬PGT-N19~d1.jpg

Thank you so much.

jupe
Posts: 2809
Joined: 20 Oct 2017 21:14
Location: Win10 22H2 120dpi

Re: EXIF Conditional Rename

Post by jupe »

Let me preface this by saying I have been implementing your requests by trying to keep the required changes to the original as minimal as possible, and in one self contained add-on section, this isn't the best way of achieving what you want, and certainly not the most efficient, anyway you could try something like this, yet again it is totally untested though, it replaces previous suggestion in the same place.

Code: Select all

  $colBase  = regexreplace($pattern, "(\.[^.]+?)$");
  $extFiles = <crlf> . quicksearch("$colBase*.$extension /fn", gpc($item, "path"),, n);
  $cntCol   = gettokenindex($colBase . "*",  $previewNames . $extFiles, <crlf>, "iwc");
  if ($cntCol) { $pattern = regexreplace($pattern, "(\.[^.]+?)$","~d". $cntCol . "$1"); }
It will probably still fail under certain obscure conditions with your weird naming scheme, especially if you do things like delete ~d2 but keep ~d3. But you are going to have to learn scripting yourself if you want it to work in every imaginable scenario, I am not capable enough to keep modifying this without test files or testing.

aimy
Posts: 186
Joined: 26 Feb 2007 15:44

Re: EXIF Conditional Rename

Post by aimy »

jupe wrote: 25 Apr 2024 08:03 Let me preface this by saying I have been implementing your requests by trying to keep the required changes to the original as minimal as possible, and in one self contained add-on section, this isn't the best way of achieving what you want, and certainly not the most efficient, anyway you could try something like this, yet again it is totally untested though, it replaces previous suggestion in the same place.

Code: Select all

  $colBase  = regexreplace($pattern, "(\.[^.]+?)$");
  $extFiles = <crlf> . quicksearch("$colBase*.$extension /fn", gpc($item, "path"),, n);
  $cntCol   = gettokenindex($colBase . "*",  $previewNames . $extFiles, <crlf>, "iwc");
  if ($cntCol) { $pattern = regexreplace($pattern, "(\.[^.]+?)$","~d". $cntCol . "$1"); }
It will probably still fail under certain obscure conditions with your weird naming scheme, especially if you do things like delete ~d2 but keep ~d3. But you are going to have to learn scripting yourself if you want it to work in every imaginable scenario, I am not capable enough to keep modifying this without test files or testing.
You're such a brilliant!!

Thanks so much!!!

Yes it really works as intended!!

Million of thanks.. :cup: :cup: :cup:

Post Reply