ExifTool Forum

General => Other Discussion => Topic started by: victorengel on June 18, 2021, 11:32:14 AM

Title: Suggestions for how to tackle this renaming scheme
Post by: victorengel on June 18, 2021, 11:32:14 AM
Two cards, one was for raw files, one for jpeg files. The one with raws had issues, and a recovery using Lexar recovery tool recovered the files with names like f# where # is a sequential number, apparently. The other card is fine. I'd like to use the jpeg files as a guide to how to rename the recovered raw files.

My first thought is to do something like this:
* Store current filename into an EXIF field in the jpeg files. Let's call this field NEWFIELD
* Rename all files according to Date/Time Original.
* Write a script that loops through all jpeg files.

For each file:
* Capture the filename without extension.
* Extract the EXIF field value written from the first step
* Rename filename.cr2 to NEWFIELD.cr2

Do you see a problem with this scheme? Do you know of a simple way to implement it?
Title: Re: Suggestions for how to tackle this renaming scheme
Post by: StarGeek on June 18, 2021, 12:17:55 PM
Quote from: victorengel on June 18, 2021, 11:32:14 AM
My first thought is to do something like this:
* Store current filename into an EXIF field in the jpeg files. Let's call this field NEWFIELD

I'd suggest XMP:PreservedFileName, optionally XMP:Title and IPTC:ObjectName.  The latter two are the placement recommended by the IPTC Photo Metadata Standard (https://www.iptc.org/std/photometadata/specification/IPTC-PhotoMetadata#title) but Lightroom ignores this recommendation in favor of the first tag.

Quote* Write a script that loops through all jpeg files.

Sidenote, looping exiftool in a script is Common Mistake #3 (https://exiftool.org/mistakes.html#M3).  It is slow and almost never required.

I would suggest this sequence
Copy filename without extension into tag, this assumes you're using at least exiftool ver 12.22 or higher
exiftool "-XMP:PreservedFileName<BaseName" /path/to/jpegs/

Rename all files using SubSecDateTimeOriginal, as that will be less likely to have duplicate names.  Test it out first with Testname, then change to Filename if it looks correct.  Note that you can do both directories in one command
exiftool "-TestName<${SubSecDateTimeOriginal;}.%e" /path/to/jpegs/  /path/to/cr2s/

Copy tag and rename.  Again, testing first then change if looks good
exiftool -TagsFromFile /path/to/jpegs/%f.jpg "-Testname<$XMP:PreservedFileName.%e" /path/to/cr2s/

Rename jpegs back to original
exiftool "-Filename<$XMP:PreservedFileName.%e" /path/to/jpegs/

Test the whole thing out first, but this should work.
Title: Re: Suggestions for how to tackle this renaming scheme
Post by: victorengel on June 18, 2021, 01:01:14 PM
Thanks. I'm glad I asked. I'll try this out when I next have time.
Title: Re: Suggestions for how to tackle this renaming scheme
Post by: victorengel on June 18, 2021, 01:46:53 PM
I'm getting an error on the second command:

exiftool "-TestName<${SubSecDateTimeOriginal;}.%e" ./JPG/ ./CR2/
zsh: bad substitution

I am doing this from the parent directory of JPG and CR2 directories.
Title: Re: Suggestions for how to tackle this renaming scheme
Post by: Phil Harvey on June 18, 2021, 02:03:40 PM
Use single quotes instead of double quotes (see my signature).

- Phil
Title: Re: Suggestions for how to tackle this renaming scheme
Post by: StarGeek on June 18, 2021, 02:11:33 PM
Also the first bullet point in my sig  ;)
Title: Re: Suggestions for how to tackle this renaming scheme
Post by: victorengel on June 18, 2021, 03:20:28 PM
I saw that but promptly forgot. Works like a charm, but I'll change the last step to delete the jpegs because they've already been archived, so they're just temporary.