Assign parts of FileName to xmp:UserComment

Started by User_, August 16, 2022, 05:22:44 PM

Previous topic - Next topic

User_

My files are named like
"2019_10_28_112702_IMG_2898.mp4"
. How can assign
"IMG_2898"
to xmp:UserComment?

Tried variations of
"-XMP-exif:UserComment<${FileName;s/\d{17}_(d{8})/$1/}"
but did not succeed :-)

Thank you for your help!

StarGeek

Will all the files have "IMG_(number)" as the data you're trying to pull or might there be something else.

Assuming the former, you could use
exiftool "-XMP:UserComment<${Filename;m/(img_\d+)/i;$_=$1}" /path/to/files/

This attempts to match and capture "img(underscore)(1 or more numbers)", case insensitively.

To break down what your original attempt actually did, the \d tried to match numbers only and the {17} required 17 of them.  The underscores blocked that match.  Assuming the second part was supposed to be \d{8}, that would have been the same except it was looking for 8 numbers.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

User_

All files ended with "IMG_(number)" and your proposed command worked good!

Thank you very much!