File renaming and storing new name in tag

Started by krdavies, May 20, 2012, 05:48:09 AM

Previous topic - Next topic

krdavies

I'm trying to rename files and to store the base of the new name in the Title tag:

exiftool.exe "-filename<${DateTimeOriginal}-%.c.%le" -d "%Y%m%d-%H%M%S" FILE
exiftool.exe "-title<$basename" FILE


Is there a way of doing this in one exiftool execution? It appears that adding "-title<${DateTimeOriginal}-%.c" to the first command is not available because of the copy number.

Phil Harvey

Right.  The %d, %f, %e and %c are special only when exiftool expects a file name, so they have no special meaning when writing Title.  And the special characters are interpreted in the file name much later in the processing, after Title is written.  So unfortunately I can't think of any way to do what you want in a single command.

- 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 ($).

ryerman

I would have tried the -execute option.  Is that not applicable in this case?

Jim
Windows 10 Home 64 bit, Exiftool v12.61

krdavies

Thank you for confirming that, Phil.

Jim, I did try various combinations of options and -execute, but without success.

Keith

Phil Harvey

#4
Jim is correct that any number of commands can be executed in one command line with -execute.  The number of processing steps is the same, but the startup costs of the extra command are avoided.  In this case, however, determining the file name in advance for the 2nd command would be a problem, unless you can specify a directory name (to process an entire directory of files) instead of a file name on the command line.

If you wanted to be really sneaky, you could do something like this:

exiftool.exe "-celltowerid<directory" "-filename<tmp/${DateTimeOriginal}-%.c.%le" -d "%Y%m%d-%H%M%S" FILE -execute "-directory<celltowerid" "-title<basename" -celltowerid= tmp

Which stores the directory name temporarily in an obscure XMP tag (CellTowerID), then moves the file to a directory named "tmp" and renames it, then adds the Title tag and moves the file back to the original directory in the 2nd command.  This won't be much faster though, because it involves writing the file twice (instead of just renaming once and writing once).

- Phil

Edit: Added sneaky command

Edit2: Removed "$" from "basename" (not necessary when just copying a tag directly)

Edit3: Just for fun I tried this command, and realize now that it will duplicate the file twice since it edits some tags each time.  Adding -common_args -overwrite_original to the end of the command (as if it wasn't complicated enough already) will delete the originals after each step.
...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 ($).

krdavies

Wow! That's impressive. I think I'll stick with two commands, if only to avoid confusion if I have to amend it in the future. I've learned a lot about -execute though!

Keith

bestsides

 :) I, too, wanted to say thank you for this post and particularly the detailed answers and explanations by Phil/Jan I am in the same situation as the MacOS Finder Created dates changed as the result of writing metadata to file in LR after keywording digital graphic design images. I can use the commands here (I hope!) to fix these dates {incidentally} by fixing the Modified Finder dates. It will save a ton of time and pacify my OCD issues.