Exiftool: Rename From Date
I got a GoPro recently and it names the files with seemingly random combination
of some letters and numbers. I have gotten quite used to my phone naming photos
as DATE_TIME.jpg
. It just makes more sense to me. Luckily, the date and time
are still set in the EXIF tags and those can be used to rename the file.
Using exiftool
, the renaming is one magic incantation away.
Add a -verbose
flag to have it tell you what each file is renamed to.
exiftool -d '%Y%m%d_%H%M%S%%-c.%%e' '-filename<CreateDate' .
Let’s unpack what happens here.
The -d
flag is to specify how to format the date. The first 6 %
might be
familiar to you if you are a programmer: %Y
is the year in four numbers, %m
is zero padded month, %d
is zero padded day of the month, %H
is zero padded
hour, %M
is zero padded minutes, and %S
is zero padded seconds. %%-c
is
one thing. The double %
is to escape the date formatting and drop back to
regular exiftool formatting. In regular exiftool formatting, the %-c
will add
a copy number if two filenames would otherwise overlap (in our case: they were
taken in the same second). It adds a dash and a number to the second file (or
third file, and so on). The %%e
is again one thing with double %
dropping
back to regular exiftool formatting. In that formatting, %e
is the file’s
extension.
The other flag reads the CreateDate
field out of the EXIF tags and writes it
(<
) to the filename
.
The final .
tells exiftool to process the directory, you can also pass in
specific files instead.
A file is thus renamed to, for example, 20240720_121232.jpg
. If a second
photo was taken in that same second, it will be named 20240720_121232-1.jpg
.
Note that the exiftool manpage has some more details about the %c
formatter:
For %c, these modifiers have a different effects. If a field width is given, the copy number is padded with zeros to the specified width. A leading ‘-‘ adds a dash before the copy number, and a ‘+’ adds an underline. By default, the copy number is omitted from the first file of a given name, but this can be changed by adding a decimal point to the modifier. For example:
-w A%-cZ.txt # AZ.txt, A-1Z.txt, A-2Z.txt ... -w B%5c.txt # B.txt, B00001.txt, B00002.txt ... -w C%.c.txt # C0.txt, C1.txt, C2.txt ... -w D%-.c.txt # D-0.txt, D-1.txt, D-2.txt ... -w E%-.4c.txt # E-0000.txt, E-0001.txt, E-0002.txt ... -w F%-.4nc.txt # F-0001.txt, F-0002.txt, F-0003.txt ... -w G%+c.txt # G.txt, G_1.txt G_2.txt ... -w H%-lc.txt # H.txt, H-b.txt, H-c.txt ... -w I.%.3uc.txt # I.AAA.txt, I.AAB.txt, I.AAC.txt ...