ExifTool Forum

ExifTool => Newbies => Topic started by: yann.boudreau on September 10, 2017, 10:26:08 AM

Title: How to Organize/Rename Files in Directory Structure using the Description tag?
Post by: yann.boudreau on September 10, 2017, 10:26:08 AM
Hello,

I would like to automatically create a folder structure and rename my files based on the following format:

Original file:
something.jpg

Desired Output file would follow this directory structure:
YYYY/YYYY-MM_DescriptionTag/YYYY-MM-DD_HHmmSS.jpg

I tried this command which works great but I cannot find a way to name folders using the Description tag without error:

exiftool -P -d %Y/%Y-%m/%Y-%m-%d_%H%M%S.%%e "-filename<datetimeoriginal" .

Any help would be much appreciated!

Many thanks.
Title: Re: How to Organize/Rename Files in Directory Structure using the Description tag?
Post by: StarGeek on September 10, 2017, 10:41:35 AM
Unfortunately, you can't insert a tag into the middle of the -d option.  But as of ver 10.49 there is an option to format the date using the Advanced Formatting Feature.

Try this, but try it out first on a test file or using Testname instead of Filename
exiftool -P "-filename<${datetimeoriginal;DateFmt('%Y/%Y-%m')}_$Description/${datetimeoriginal;DateFmt('%Y-%m-%d_%H%M%S.%%e')}"
Title: Re: How to Organize/Rename Files in Directory Structure using the Description tag?
Post by: yann.boudreau on September 10, 2017, 10:53:25 AM
Hi,

I tried the following command to run a test as suggested:

exiftool -P "-testname<${datetimeoriginal;DateFmt('%Y/%Y-%m')}_$Description/${datetimeoriginal;DateFmt('%Y-%m-%d_%H%M%S.%%e')}" .

and got the following return:

-bash: -testname<${datetimeoriginal;DateFmt('%Y/%Y-%m')}_$Description/${datetimeoriginal;DateFmt('%Y-%m-%d_%H%M%S.%%e')}: bad substitution

I am using a Mac.
Title: Re: How to Organize/Rename Files in Directory Structure using the Description tag?
Post by: StarGeek on September 10, 2017, 11:29:18 AM
On Mac/Linux, you need to reverse the double/single quotes.

exiftool -P '-filename<${datetimeoriginal;DateFmt("%Y/%Y-%m")}_$Description/${datetimeoriginal;DateFmt("%Y-%m-%d_%H%M%S.%%e")}'
Title: Re: How to Organize/Rename Files in Directory Structure using the Description tag?
Post by: yann.boudreau on September 10, 2017, 11:42:37 AM
Many thanks for the quick answer!

I noticed that the program does not process files that do not have a $description tag assigned.
Is there a way to force this behaviour and follow the same directory structure even when the tag is not assigned?
Do I need to manually assign "" to the $description tag of all my files to ensure they are all processed?

Thank you!
Title: Re: How to Organize/Rename Files in Directory Structure using the Description tag?
Post by: StarGeek on September 10, 2017, 12:02:32 PM
From the docs (https://exiftool.org/exiftool_pod.html#TAG---VALUE), note 1 on tags:
"Many tag values may be assigned in a single command. If two assignments affect the same tag, the latter takes precedence "

So if we do a copy without the Description tag followed by one with the tag, for any file that actually has a Description tag, the second assignment will take precedence.  Files without a Description tag won't be affected the the second assignment.  Though it does start to look messy at that point.

exiftool -P '-filename<${datetimeoriginal;DateFmt("%Y/%Y-%m")}/${datetimeoriginal;DateFmt("%Y-%m-%d_%H%M%S.%%e")}' '-filename<${datetimeoriginal;DateFmt("%Y/%Y-%m")}_$Description/${datetimeoriginal;DateFmt("%Y-%m-%d_%H%M%S.%%e")}'

Files without the Description tag will throw a Warning: [minor] Tag 'Description' not defined but that can be ignored.
Title: Re: How to Organize/Rename Files in Directory Structure using the Description tag?
Post by: yann.boudreau on September 10, 2017, 04:37:04 PM
Works as a charm!
Many thanks for your prompt and detailed response.

Regards,

Yann.