renaming - rename pattern inconsistent, -d and -filename

Started by tcris, August 19, 2016, 07:39:53 AM

Previous topic - Next topic

tcris

Hello,

thanks for the great tool, PH!

I am a bit confused about the filename syntax when renaming photos.

(part of) the syntax for the new filename can be specified either
- in the -filename argument, or
- in the -d argument

e.g. I can specify %c or %e in both

This means
- the -d does not really specify just! the date/time.
- the -filename does not really specify the full filename.


Is there an orthogonal way to say something like

exiftool "-filename<${createdate.year}-${createdate.month}-${createdate.day} ${model;}-%c.%e" INPUT_DIR

without relying on the -d?

Thanks
Chris

Phil Harvey

Hi Chris,

It should be clear:

-d option formats date/time tags.  It has nothing to do with the file name unless you copy a date/time tag to the file name.

%d, %f, %e and %c only have a special meaning when written to a file name.

You can do what you want without -d, but it would require some advanced formatting expressions to convert a date/time value into the format you want.

- 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 ($).

tcris

Hi,

Yes, according to docs
-d FMT      (-dateFormat)        Set format for date/time values

but then I see this example
exiftool -d %Y%m%d_%H%M%%-c.%%e "-filename<CreateDate" DIR

where %c and %e are both part of the -d 'format' (yet, %c and %e are unrelated to the date/time format)

So ,this is the first and minor issue I see. (-d doing more than just specifying the date/time format).

Note that the -filename argument here is very simple, only specifies CreateDate.
Still, the generated filename will be more complex due to the -d format.
Because the file name is *here* generated by both -filename and -d.

Ok, got it!



But 5 seconds later, looking at a different example I see
exiftool "-filename<${model;}.%e" c:\images

This time the filename is fully(?) specified by -filename.
Both an exif field (this time is the Model, not the CreateDate) and a placeholder are specified here.
Nice! So we can actually do much more with -filename (than in the 1st example), and specify the whole(?) filename pattern.
The keyword here is the *whole*.

I see a placeholder as part of -filename in the second example (%e which also appears in -d, why support it in two places? but let's move on).
I also see an exif field.
So can I use any field, just here, in -filename?

Apparently not, because date/time fields need extra splitting.

My suggestion:
If I could only use (fragments of) date/time fields here, the same way I use the model field, here, in -filename.
That would be nice to have: one, and only one way of dealing with file names.
- Do not allow %c or %e in different options (-d vs -filename).
- Do not require special options for composite fields(like -d for date/time ones)

exiftool "-filename<${createdate.year}-${createdate.month}-${createdate.day} ${model;}-%c.%e" INPUT_DIR

Yes, I am aware that this would require to allow parsing something like ${CreateDate.%Y} to refer to fragments of the full field (CreateDate comes as a string).

Yes, what I suggest is just another syntax, but is
orthogonal (where date format and file name are not interdependent at all) and
uniform (no special options required for datetime)

Yes, 'extra ' parsing is needed but could be useful with other composite fields as well.
And is not really so 'extra' if you count the parsing you already do for -d, right now.

so it's a matter of both style (easier to read)...
and also functionality: it would allow splitting any field into fragments and then combine fragments, even from different fields, into a single pattern.
e.g. use the year from CreateDate and the hour from DateOriginal (yeah, terrible example, but you get the idea)

just my two cents :)

I know this has no chance to be implemented; I just wanted to ask if I can use a datetime without -d, straight in -filename (and the current answer is no).
And validate my idea.

thanks for your time, PH
Chris

Phil Harvey

#3
Hi Chris,

Quote from: tcris on August 19, 2016, 09:41:50 AM
but then I see this example
exiftool -d %Y%m%d_%H%M%%-c.%%e "-filename<CreateDate" DIR

where %c and %e are both part of the -d 'format' (yet, %c and %e are unrelated to the date/time format)

Technically, %c and %e are not part of the -d format.  It is %% that represents a single percent character that is part of this format.  The date/time formatting couldn't care less about what comes after the %%.  Then in this example you are writing something like this to FileName:

  20160819_0959%-c.%e

Which is the same as this command:

  exiftool -filename=20160819_0959%-c.%e ...

The %-c and %e are then interpreted when writing to FileName.  If written to any other tag (ie. Comment), then the %-c and %e are taken literally.

QuoteBut 5 seconds later, looking at a different example I see
exiftool "-filename<${model;}.%e" c:\images

Yes, you can use any combination of tags when copying.  This is just the -tagsFromFile feature, and is not specific to writing FileName (although FileName interprets the special format codes %d, %f, %e and %c  that other tags do not).   The ability to set the file name arises organically from the exiftool design -- the same ability may be used to write any other tag.

- Phil

P.S.  You can use a date/time tag directly in a file name, but not in Windows because Windows file names may not contain a colon.  Using -d gets around that problem.  You could just as well use an advanced formatting expression to do this (these may be used for any tag), but it is more difficult.
...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 ($).

tcris

thanks a lot PH

I guess I understand a bit more about how exiftool works
1st pass: -d replaces format with actual date/time values taken from exif
2nd pass: the resulting format is piped from -d to -filename which does further processing
nice to know that

can you point a small (linux) example about using datetime fields in -filename? just wondering how is done

great support! thanks a lot
Chris

Phil Harvey

...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 ($).