How do I write only the last part of the file name to a tag?

Started by Jom, March 26, 2020, 07:11:21 AM

Previous topic - Next topic

Jom

How do I write only the last part of the file name to a tag?

I have a file with 10 in last part of name
20131111_205640_10.psd
and I only need to write 10 in the tag -exif:usercomment.

Thanks.

Phil Harvey

To write the last 2 digits:

exiftool "-exif:usercomment<${filename;s/.*(\.{2})\..*/$1/}" DIR

To write the number after the last underline:

exiftool "-exif:usercomment<${filename;s/.*_(\d+)\..*/$1/}" DIR

... there are many other possibilities.

Note that both of these command will write the entire file name if the pattern does not match.  The last command above could be altered like this if you want to write nothing in this case:

exiftool "-exif:usercomment<${filename;s/.*_(\d+)\..*/$1/ or $_ = undef}" DIR

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

Jom

Thank you, I will try to do this.
Can I use regular expressions within ExifTool without restrictions, as usual?

Phil Harvey

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