Main Menu

Rename a file by Tags

Started by Quant007, February 01, 2020, 11:20:22 AM

Previous topic - Next topic

Quant007

Hallo,
i would like to rename my files by using a ARG-File. The filename should look like "2020-02-01_18:15:20.jpg". If there any title in the tags, the filename should look like "2020-02-01_18:15:20-Title.jpg". My ARG-File is here:

-FileName<CreateDate
-d
%Y-%m-%d_%H-%M-%S%%-c.%%e
-if "(($title) and ($datetimeoriginal))"
-FileName<CreateDate
-d
%Y-%m-%d_%H-%M-%S%%-c-${Title}.%%e

What I get is "1991-03-14_09-34-25-${Title}.jpg"

How can I do this right?

Thanks for help.

StarGeek

You can't add a tag name to a date format string.  So you have to separate that part out.  That means moving the extension variable %e out of the date string.

Additionally, you have to put each argument on separate lines and you don't include quotes.  That means the -if "(($title) and ($datetimeoriginal))" needs to be separated.

Also, make sure there are no trailing spaces

I haven't tested it, but try this.
-FileName<CreateDate
-d
%Y-%m-%d_%H-%M-%S%%-c.%%e
-if
(($title) and ($datetimeoriginal))
-FileName<$CreateDate-$Title.%e
-d
%Y-%m-%d_%H-%M-%S%%-c


Now, on the second part of that arg file, you are testing for DateTimeOriginal, but copying from CreateDate.  Are you sure you don't want to copy from DateTimeOriginal instead?
* 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).

Quant007

Thanks for your repley and your tip. This was a fault, now it works perfekt, but i have to change the first statment in

-FileName<$DateTimeOriginal.%e
-d
%Y-%m-%d_%H-%M-%S%%-c

With the old statment it doesent work, thatswhy on additional question:
If I had a foto with no title, then it will renamed without an extension. It seems, that the last d- Parameter (%Y-%m-%d_%H-%M-%S%%-c) ist use although I have no title.
I thougt, that every option after the If - statment ist only used when I have a title.
The goal is a statement like
If (($Title) and ($DateTimeOriginal)) then
-FileName<$DateTimeOriginal-$Title.%e
-d
%Y-%m-%d_%H-%M-%S%%-c
else
-FileName<DateTimeOriginal
-d
%Y-%m-%d_%H-%M-%S%%-c.%%e
endif
Any ideas for that?

Quant007

One additional question:
Is ther any possibility:
When I use this statment

-FileName<$DateTimeOriginal-$Title.%e
-d
%Y-%m-%d_%H-%M-%S%%-c

if i had a blanc space in a title so the filename contains also blanc spaces.
Can i replace it with "_"?

Phil Harvey

Yes.

Use ${title;tr/ /_/} instead of just $title

But you have to be careful of other characters in the title as well.  Particularly a "/" will cause problems, and other characters depending on your operating system.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Quant007

Hello,
is there any idea to reply #2

Thanks for help

Phil Harvey

Quote from: Quant007 on February 02, 2020, 01:32:42 PM
The goal is a statement like
If (($Title) and ($DateTimeOriginal)) then
-FileName<$DateTimeOriginal-$Title.%e
-d
%Y-%m-%d_%H-%M-%S%%-c
else
-FileName<DateTimeOriginal
-d
%Y-%m-%d_%H-%M-%S%%-c.%%e
endif
Any ideas for that?

You do it like this:


-d
%Y-%m-%d_%H-%M-%S%%-c
-FileName<$DateTimeOriginal.%e
-FileName<$DateTimeOriginal-$Title.%e


- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).