Rename jpeg files to contain the date the picture was taken

Written by - 0 comments

Published on - last updated on August 4th 2019 - Listed in Windows Linux Multimedia Mac

I have a ton of pictures on my mobile phone. From time to time I put them on my central backup machine. However I came across a few issues when I wanted to sort them (for example when I wanted to create a family album):

  • The filenames are often just a file counter. For example the camera just counts the picture number up like DSC0001, DSC0002, DSC0003 etc. Somewhere in Android this can (sometimes) be changed in the settings where the file name should contain the date.
  • When I moved pictures from the internal memory to the external (SD card) memory, all picture's file dates were changed to the day the files were moved. 
  • Manually trying to find the original date and then rename the pictures takes hours.

Luckily I came across jhead. An open source tool, written by Matthias Wandel, which can be used on all platforms. For Windows, Linux and Mac OS X there's a pre-compiled executable file which can be launched from the command line (no graphical interface).

jhead is able to read the Exif JPEG headers which still (should) contain the original date the picture was taken. For example:

D:\Downloads\Grafik\JHead>jhead.exe D:\tmp\DSC*
File name    : D:\tmp\DSC_0261.JPG
File size    : 3264489 bytes
File date    : 2016:03:24 12:50:06
Camera make  : Sony
Camera model : D6503
Date/Time    : 2016:02:13 12:17:55
Resolution   : 3840 x 2160
Flash used   : No
Focal length :  4.9mm
Exposure time: 0.0010 s  (1/1000)
Aperture     : f/2.0
ISO equiv.   : 50
Whitebalance : Auto
Metering Mode: pattern
GPS Latitude : ? ?
GPS Longitude: ? ?
JPEG Quality : 97

( Yes, for once I'm on a Windows OS )

As you can see above, the file date and the date/time differ. The "File date" represents the date the picture was moved from the phone's internal memory to the SD card. The "Date/Time" value represents the date and time when the picture was taken.

But jhead is not only able to read the Exif JPEG headers. It comes with a function (-n) to rename the JPEG file using certain variables. In the following example I renamed all files starting with DSC in the folder D:\tmp using the Exif JPEG Date/Time in the format Month-Day-Year-Filename (%m-%d-%Y-%f):

D:\Downloads\Grafik\JHead>jhead.exe -n%m-%d-%Y-%f D:\tmp\DSC*
D:\tmp\DSC_0261.JPG --> D:\tmp\02-13-2016-DSC_0261.jpg
D:\tmp\DSC_0262.JPG --> D:\tmp\02-13-2016-DSC_0262.jpg

Jpeg photos renamed to date picture was taken

The result is exactly what I needed: The date the picture was taken is now the prefix of the filename, followed by the original filename. Finally I'm able to quickly and properly sort all kinds of pictures - even when they were taken by different cameras and had different filenames.

On Linux the command is almost the same, just without the .exe suffix:

root@nas:/srv/data/Pictures/Ystad 2019# jhead -n%m-%d-%Y-%f DSC*
DSC_0001.JPG --> 04-08-2019-DSC_0001.jpg
DSC_0010.JPG --> 04-10-2019-DSC_0010.jpg
DSC_0016.JPG --> 04-11-2019-DSC_0016.jpg
DSC_0018.JPG --> 04-12-2019-DSC_0018.jpg
DSC_0019.JPG --> 04-12-2019-DSC_0019.jpg
DSC_0020.JPG --> 04-12-2019-DSC_0020.jpg
DSC_0021.JPG --> 04-12-2019-DSC_0021.jpg
DSC_0022.JPG --> 04-12-2019-DSC_0022.jpg
DSC_0023.JPG --> 04-12-2019-DSC_0023.jpg
DSC_0024.JPG --> 04-12-2019-DSC_0024.jpg
DSC_0025.JPG --> 04-12-2019-DSC_0025.jpg
DSC_0028.JPG --> 04-12-2019-DSC_0028.jpg

Add a comment

Show form to leave a comment

Comments (newest first)

No comments yet.