Rename files using first x chars of a tag

Started by mrkphth, May 22, 2023, 06:44:50 PM

Previous topic - Next topic

mrkphth

I run the following command.


exiftool -d %Y.%m.%d(%I.%M.%p) "-testname<${CreationDate}_$ContentIdentifier.%le" "E:\Pictures\IMG_5999.mov"

I only want to use the first 8 chars $ContentIdentifier in the new name of the file.

Any assistance is appreciated.

StarGeek

You would have to use the Advanced formatting feature and insert some Perl code, of which there are many ways to do that

For example
exiftool -d %Y.%m.%d(%I.%M.%p) "-testname<${CreationDate}_${ContentIdentifier;s/^(.{8}).*/$1/}.%le" "E:\Pictures\IMG_5999.mov"

Heh, literally the same question from  StackOverflow.  You would just use it on the default value of the tag which is $_

exiftool -d %Y.%m.%d(%I.%M.%p) "-testname<${CreationDate}_${ContentIdentifier;$_=substr($_, 0, 8 )}.%le" "E:\Pictures\IMG_5999.mov"

I learned most of what I know of Perl from googling what I want to do and "perl".  This is what I used here.  Even though I knew I wanted to use substr, I wasn't quite sure of the parameters so I had to double check.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

mrkphth

Thanks for the assistance. Used the second option. Works like a charm.