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:
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.
Thank you.
EXIF Conditional Rename
Re: EXIF Conditional Rename
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
directly before this line:
I'll leave it up to you to escape the string if you feel it necessary. Totally untested aircode.
Code: Select all
if (regexmatches($previewNames, "^$pattern$")) { $pattern = regexreplace($pattern, "([^.]+?)$", "<get rs 3 0123456789>.$1"); }
$previewNames = $previewNames . $pattern . "<crlf>";
I'll leave it up to you to escape the string if you feel it necessary. Totally untested aircode.
Re: EXIF Conditional Rename
wow!!! it works like a charm!!!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
directly before this line:Code: Select all
if (regexmatches($previewNames, "^$pattern$")) { $pattern = regexreplace($pattern, "([^.]+?)$", "<get rs 3 0123456789>.$1"); }
$previewNames = $previewNames . $pattern . "<crlf>";
I'll leave it up to you to escape the string if you feel it necessary. Totally untested aircode.
Thank you so much jupe!!
I really appreciate it
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
Re: EXIF Conditional Rename
Sure its possible, I was leaving that up to you though.
Anyway, since you asked, something like this should work:
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.
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"); }
Re: EXIF Conditional Rename
Thanks again so much!! It really works!!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:
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.Code: Select all
$cntCol = gettokenindex(regexreplace($pattern, "(\.[^.]+?)$") . "*", $previewNames, <crlf>, "iwc"); if ($cntCol) { $pattern = regexreplace($pattern, "(\.[^.]+?)$", "_" . format($cntCol, "00") . "$1"); }
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. 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.
Re: EXIF Conditional Rename
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.
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.
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"); }
Re: EXIF Conditional Rename
You're such a brilliant!!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.
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.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"); }
Thanks so much!!!
Yes it really works as intended!!
Million of thanks..