Rename filename in accordance to tag: StackedImage value, second approach

Started by TravelPhoto, October 07, 2022, 11:08:09 AM

Previous topic - Next topic

TravelPhoto

Good day,
My original posting (nearly same subject) from 2020 Oct was answered by LUUK2005. The provided string is working great.

### exiftool -if '$StackedImage =~ /(?!No)../ and not $Filename =~ /_(ND\d[26]?|HDR[12]|(T|HH)HR|(L[CT]|FS)_\d{1,3})\.(?i)jpe?g$$/' -FILEname'<%f_${StackedImage;s/(.*) .*V\)$/$1/;s/Tr.*/THR/;s/Ha.*/HHHR/;s/.*Co.*?(\d+).*/LC_$1/;s/.*Bu.*?(\d+).*/LT_$1/;s/Fo.*?(\d+).*/FS_$1/}.%e' ###

Due to new requirements I would like to get the stacking information as first part of the new filename. Unfortunately the filter / select module in my imaging software OM Workspace (formerly known as Olympus Workspace) is quite limited. I need the Stacking Information as first part of the file name for more convenient sorting.

I have tried to change the string by my self by moving the "%f_" (I'm guessing this ist the original filename) part to the far end behind the "}" as "_%f"
It was not working. Mostly the answer is "Quote"
I 've tried to use all types of brackets and quotes, reading the FAQ and exiftool manual as well as a basic training information about PERL.  I can't get the point. I am pretty sure the solution is very simple :-)
Please find attache a image with stacking information.

Thanks for your help and best regards,
Bernd

MacBookPro12,1, macOS MOnterey Version 12.6 (21G115)
EXIFTOOL Ver: 12.47
OM Workspace Ver: 2.0.1
Olympus OM-D EM 1 Mark 3 and OM-D EM 1X both updated to newest firmware

StarGeek Edit: Edited to correct formatting
Camera: Olympus OM-D E-M1 Mark III, Olympus OM-D E-M1X, Olympus OM-D E-M10 Mark II
EXIFTOOL Version: 12.47, MacBook Pro 13" MacOS: Monterey (12.6)

StarGeek

Quote from: TravelPhoto on October 07, 2022, 11:08:09 AMI have tried to change the string by my self by moving the "%f_" (I'm guessing this ist the original filename) part to the far end behind the "}" as "_%f"
It was not working. Mostly the answer is "Quote"

That should be the correct solution.  I would quote it differently though
exiftool -if '$StackedImage =~ /(?!No)../ and not $Filename =~ /_(ND\d[26]?|HDR[12]|(T|HH)HR|(L[CT]|FS)_\d{1,3})\.(?i)jpe?g$$/' '-FILEname<${StackedImage;s/(.*) .*V\)$/$1/;s/Tr.*/THR/;s/Ha.*/HHHR/;s/.*Co.*?(\d+).*/LC_$1/;s/.*Bu.*?(\d+).*/LT_$1/;s/Fo.*?(\d+).*/FS_$1/}_%f.%e'

Hard to tell what is going wrong without seeing the exact command and output copy/pasted here.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

TravelPhoto

Hi StarGeek,

Thanks for providing the solution.
Quite interessting, just moving the single quote in front of the "-FILENAME......" string and the issue is solved. Is it possible to explain, why the old statment is working with the single quote just behind "-FILENAME". Unfortunately I am far away to be a programmer and it is quite tricky for mee to understand these strings with all the commands included. But I am trying my very best.

Thanks again.

Bernd
Camera: Olympus OM-D E-M1 Mark III, Olympus OM-D E-M1X, Olympus OM-D E-M10 Mark II
EXIFTOOL Version: 12.47, MacBook Pro 13" MacOS: Monterey (12.6)

StarGeek

The quotes are needed to let the terminal know that the less/greater than </> symbols are part of the command and not to be treated as a terminal redirection command.  Technically, putting them around the </> should be all that's needed, but I find that unintuitive.  Putting the quotes around the whole thing makes it clear that this is a single command argument.

Single quotes are also needed around anything with a dollar sign in terminal.  Otherwise, the terminal thinks it's the start of a terminal variable.

While double quotes can be used in other cases in terminal, it's a better habit to just use single quotes, IMO.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

TravelPhoto

#4
While looking at the list of tags for the Olympus images, I've found the "Rating" tag. I would like to set the rating value to "1" for each image in addition to the file name change.

In accordance to ExifTool Command-Line Examples #4: exiftool -artist="Phil Harvey" -copyright="2011 Phil Harvey" a.jpg

my test images: OldName.jpg  and OldName_1  both Rating values are 3

my first idea was:

exiftool -if '$StackedImage =~ /(?!No)../ and not $Filename =~ /_(ND\d[26]?|HDR[12]|(T|HH)HR|(L[CT]|FS)_\d{1,3})\.(?i)jpe?g$$/' '-FILEname<${StackedImage;s/(.*) .*V\)$/$1/;s/Tr.*/THR/;s/Ha.*/HHHR/;s/.*Co.*?(\d+).*/LC_$1/;s/.*Bu.*?(\d+).*/LT_$1/;s/Fo.*?(\d+).*/FS_$1/}_%f -rating=1.%e' /Users/Bernd/Desktop/OldName_1.jpg
1 image files updated

Result: new filename is: FS_8_OldName -rating=1.jpg  Rating is still 3 -> NOT OK

second try:

exiftool -if '$StackedImage =~ /(?!No)../ and not $Filename =~ /_(ND\d[26]?|HDR[12]|(T|HH)HR|(L[CT]|FS)_\d{1,3})\.(?i)jpe?g$$/' '-FILEname<${StackedImage;s/(.*) .*V\)$/$1/;s/Tr.*/THR/;s/Ha.*/HHHR/;s/.*Co.*?(\d+).*/LC_$1/;s/.*Bu.*?(\d+).*/LT_$1/;s/Fo.*?(\d+).*/FS_$1/}_%f.%e' -rating=1 /Users/Bernd/Desktop/OldName.jpg
    1 image files created

Result: filename and rating for old image are unchanged
new image created: File name: FS_8_OldName.jpg and rating = 1 are as expected

But why is the new file created, instead of updating the tags -Filename and -Rating to the original file?

Please find attached 4 image files.
OldName.jpg Rating = 3  -> new file: FS_8_OldName.jpg  Rating = 1
OldName_1.jpg Rating = 3 -> changed file: FS_8_OldName_1 -rating=1.jpg Rating = 3


Thanks for helping again.

Best regards Bernd

StarGeek Edit: Edited to correct formatting.
Camera: Olympus OM-D E-M1 Mark III, Olympus OM-D E-M1X, Olympus OM-D E-M10 Mark II
EXIFTOOL Version: 12.47, MacBook Pro 13" MacOS: Monterey (12.6)

StarGeek

See "Notes" on the Writing "FileName" and "Directory" tags page.
    Writing the FileName and/or Directory tags alone causes the file to be renamed or moved, not copied. However, if any "real" tags are written at the same time, then the file is rewritten to the new destination and the original file is left unchanged
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

Phil Harvey

Add the -overwrite_original option if you don't want to keep the original file.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

TravelPhoto

Thanks a lot. It is working now.
There is so much do read about the whole Exiftool structure and more important, to understand the content :-)
Camera: Olympus OM-D E-M1 Mark III, Olympus OM-D E-M1X, Olympus OM-D E-M10 Mark II
EXIFTOOL Version: 12.47, MacBook Pro 13" MacOS: Monterey (12.6)