5

I would like to rename my photos using exiftool. This is my desired folder structure:

YYYY/
  MM/
    EVENT/
      YYYYMMDD_HHMMSS.ext

Here is an example script for what I would like to do:

echo 'Name of event?'
read event
exiftool -r '-FileName<CreateDate' -d '%Y/%m/%event/%Y%m%d_%H%M%S%%-c.%%le' .

Unfortunately, this does not work. How can I incorporate the name of the event in my folder structure?

5

You aren't using the variable with the user-provided input correctly. This answer assumes you're trying to run this script using a bash (or compatible) shell. If not, you'll need to refer to how to handle variables within your shell.

You need to reference the shell variable using the syntax of the shell, not the exiftool argument, and remove the single ("strong") quotes, which cause the variable reference to be a mere literal string (passing the name, not the value, to exiftool). What you actually want is:

event="EVENT"
exiftool -r '-FileName<CreateDate' -d "%Y/%m/$event/%Y%m%d_%H%M%S%%-c.%%le" .

The double ("weak") quotes will allow the correctly-referenced variable (using "$" as a prefix) to be substituted by the shell, while still protecting any whitespace in the user input.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.