ExifTool Forum

ExifTool => Newbies => Topic started by: User_ on August 16, 2022, 05:22:44 PM

Title: Assign parts of FileName to xmp:UserComment
Post by: User_ on August 16, 2022, 05:22:44 PM
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!
Title: Re: Assign parts of FileName to xmp:UserComment
Post by: StarGeek on August 16, 2022, 07:09:54 PM
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.
Title: Re: Assign parts of FileName to xmp:UserComment
Post by: User_ on August 17, 2022, 08:01:34 AM
All files ended with "IMG_(number)" and your proposed command worked good!

Thank you very much!