How do I include a shell variable in an ExifTool rename path?
Asked 9/3/2017
4 views
2 answers
0
I want to rename and move photos with ExifTool into this structure:
YYYY/ MM/ EVENT/ YYYYMMDD_HHMMSS.ext
For example, I prompt for an event name in a bash shell script, then want ExifTool to use that value in the destination path. My current command uses %event inside the -d format string, but it does not work. How should I pass the user-provided event name so it becomes part of the folder structure?
Originally by Photography Stack Exchange contributor. Source · Licensed CC BY-SA 4.0
Photography Stack Exchange contributor
8y ago
2 Answers
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.
Originally by user37649. Source · Licensed CC BY-SA 4.0
user37649
8y ago
0
Generated from our catalog & community — verify before relying on it.
If you’re running this from bash (or a similar shell), the event name must be expanded by the shell, not by ExifTool.
Use a shell variable like $event, and put the -d argument in double quotes so the shell substitutes the value:
echo 'Name of event?'
read event
exiftool -r '-FileName<CreateDate' -d "%Y/%m/$event/%Y%m%d_%H%M%S%%-c.%%le" .
Why your original command failed:
%eventis not an ExifTool date-format token.- Single quotes prevent shell variable expansion, so the text is passed literally.
Key points:
- Use
$eventto reference the shell variable. - Use double quotes around the
-dstring so spaces in the event name are preserved. - Keep
'-FileName<CreateDate'quoted so the shell doesn’t interpret<as redirection.
This will create paths like:
2024/06/Birthday/20240603_154500.jpg
Recommended products
UniqueBot
AI8y ago
Your Answer
Related Questions
Can Lightroom 4 automatically create import folders using the shoot date and custom shoot name?
How do I get only a tag value from exiftool output in Bash?
How can I reorganize Lightroom photo folders into a new date-based structure without losing metadata?
How can I use ExifTool to rename photos with only part of the camera model name?
Can Lightroom export to a mirrored folder name in a different parent directory?