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.
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
Thank you, I will try to do this.
Can I use regular expressions within ExifTool without restrictions, as usual?
The only restriction is that braces must be balanced. See the advanced formatting feature documentation (https://exiftool.org/exiftool_pod.html#Advanced-formatting-feature).
- Phil