-1

I am trying to rename all files located in a directory (recursively) with a specific meta data field appended to the end of the png file name. the meta data field name is "aesthetic_score" with a value range from 1.0-9.0

when I type:

exiftool -Aesthetic_score -G1 -s testn.png

the result is:

[PNG] Aesthetic_score : 7.0

This is how I would like to append the png files recursively within a directory. Note i would like to swap out the word aesthetic with the word chad in the append, and not all files will have this data field:

input file: filename001.png (metadata aesthetic_score:7.0)

output: filename001-chad-score-70.png

I tried to use Digikam and JExifToolGui-2.01, without success. I am trying to perform this task in the cmd line, although other solutions are welcome. Thank you for your help.

Compo
  • 36,585
  • 5
  • 27
  • 39
Konverts
  • 1
  • 1
  • None of the png I have have a tag by that name in `exiftool`'s output. Where does it come from, what does it look like in `exiftool`'s output (edit the question, paste some actual data, don't put it in the comments). What's up with the change of `aesthetic` to `chad` in the renamed file? – tink Nov 12 '22 at 23:54
  • And since I can't copy & paste a screenshot into my terminal .. how about "actual data" (as requested earlier) .. – tink Nov 13 '22 at 00:27
  • Also - are you positive that ALL the files will have the tag? – tink Nov 13 '22 at 00:28
  • [Why not to put images of code in the question?](https://meta.stackoverflow.com/a/285557/1394729) For similar reasons: don't put code (or textual output) in the comments - it loses the formatting. That information belongs in the question. – tink Nov 13 '22 at 00:41

1 Answers1

0

So, this might work for you, I can't really test it; note that you would need to get rid of the echo before the mv for it to actually do something (rename rather than just show what it would do).

while read name
do 
    newname=$(exiftool -G1 -s "$name"|awk '$2~/FileName/{name=$4}; $2~/Aesthetic_score/{basename=gensub(/^(.+)\....$/,"\\1","1",name);ext=gensub(/^.*\.(...)$/,"\\1","1",name);gsub(/\./,"",$4);print basename"."$4"."ext}')
    echo mv "$name" "$newname"
done <<<$( find -iname \*.png )

Basically the find at the very end finds all the pngs.

The while loop takes every name find throws it, and passes each file through exiftool (using your specs) and parses the output using awk, which then outputs the new name, which gets captured in the shell variable by the same name.

And finally the mv (without the echo) renames the files.

tink
  • 14,342
  • 4
  • 46
  • 50