Rename photos from the command line using EXIF date

In the Keeping photos and videos organized post I used Total Commander with Exif Plugin to rename the files based on the EXIF date. All I have to do is:

  1. Select the files I want to rename
  2. Ctrl+M to open Multi-Rename Tool
  3. Select rename mask
  4. Press enter / click Start

It works fine and takes hardly any time, but I wanted single command that does all that. After quick search I found ExifTool by Phil Harvey. There are other tools or I could have written my own but it seems this one does what I need. No need to reinvent the wheel.

I came up with the following batch file to rename all the JPG files in the current directory.

1
2
3
@ECHO OFF
set dateformat="%%Y-%%m-%%d_%%H-%%M-%%S.%%%%e"
exiftool.exe "-FileName<DateTimeOriginal" -d %dateformat% *.jpg

Assuming you have four JPG files in the current directory and the batch file is called rename_images.bat below you can see example output.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
C:\test>dir /b
DSC_0001.JPG
DSC_0002.JPG
DSC_0003.JPG
DSC_0004.JPG
C:\test>rename_images.bat
4 image files updated
C:\test>dir /b
2015-08-04_19-06-41.JPG
2015-08-04_19-08-38.JPG
2015-08-04_19-14-53.JPG
2015-08-07_16-45-08.JPG

If you have files that do not have EXIF information in them the tool just skips them.

I have renamed the original exiftool(-k).exe to exiftool.exe. This is because the -k is actually an option that is passed to the executable with the following effect.

1
2
3
C:\test>rename_images.bat
4 image files updated
-- press any key --

I don’t want to press any key so I just renamed the executable. This has been documented in the ExifTool Forums.