Append to ImageDescription causes duplication of terms

Started by c_eng, October 22, 2023, 02:00:11 PM

Previous topic - Next topic

c_eng

Hi all,

I'm a big fan of exiftool. I've been using it (at a simple level) for a few years now. I'm in the process of trying to optimise my workflow and one of the steps I want to take is to assign folder names to the ImageDescription.

In most cases the existing images have no existing description but to be safe I want to add to any existing description rather than overwrite it. I have come up with the command below which works very well with one annoying problem ... When the existing image has an existing description for some reason the new description created after running the command has the new text duplicated after the existing description. The duplication does not seem to happen if the image has no existing description.

exiftool -m '-ImageDescription<$ImageDescription ${Directory;s(\/level1\/level2\/)();s/\// /g}' -r * -overwrite_original -progress:%30b /level1/level2/ -i 'ignoredfolder' -i 'ignoredfolder2'


I've been trying various versions of the above for a number of days now and cannot seem to get past the duplication issue.

Hopefully someone can point me towards what I'm doing wrong?

Thanks in advance

Phil Harvey

Your command is appending a directory name to ImageDescription, so if ImageDescription already contains a directory name then it is duplicated.

I think the thing to do in this case is to add a -if condition to avoid processing the file in this case.  Also, if you are using -m to write the tag in the case ImageDescription doesn't exist, this will cause an extra space to be added at the start of the description.  This command may do what you want:

exiftool -if 'not $ImageDescription or $ImageDescription !~ ${Directory;s(\/level1\/level2\/)();s/\// /g}' '-ImageDescription<${Directory;s(\/level1\/level2\/)();s/\// /g}' '-ImageDescription<$ImageDescription ${Directory;s(\/level1\/level2\/)();s/\// /g}' -r -overwrite_original -progress:%30b /level1/level2/ -i 'ignoredfolder' -i 'ignoredfolder2'

Also, I have removed the "*" from the command.  Did you really want that, because you already specified the /level1/level2 directory?  If so, I recommend using "." instead of "*" for all files in the current directory.

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

c_eng

That's amazing Phil. Thanks so much.

The if statement works perfectly. I'm not sure I would have ever been able to assemble it that way myself.

You are correct about the "*" - I was originally running exiftool from inside the directory in question and now that I'm putting the command into a script I wanted to be explicit about the directory but I forgot to remove the "*"

Thanks for your great tool and your response!