Home » Blog
date 07.Oct.2018

■ Set JPG last modified dates to match date each picture was taken


When you shoot a picture with your phone or camera, it usually gets the current date and time as "last modified", a generic file date property. JPG files usually also get a special Date taken picture property, embedded in the file. Sometimes these 2 dates drift apart, e.g. if you send pictures to your PC via bluetooth, the date last modified is set to the time of the transfer (daft!). How can you repair such JPG file dates to match their actual date taken property?

xplorer² has a handy menu command Tools > Command script (press <Ctrl+B> keys) that can operate on multiple selected JPG files, but there is no DOS command I am aware of that changes file dates (linux has touch command for this purpose). There is a WSH route using the FolderItem object, but that's overly complicated and not amenable to xplorer² batch scripting.

I don't use PowerShell much (or at all I should say), but you can apparently do everything you can imagine with powershell. A little google-fu revealed the powershell command that changes time stamps. The command to change a particular file date is:

(get-item TEST.JPG).LastWriteTime = get-date '7 October 2018'

You can wrap this into a commandlet that can be run as a DOS command using powershell's -command argument. The final batch template command is this:

powershell -command "& {(get-item '$F').LastWriteTime = get-date '${Picture date}'}"

Note how we used xplorer² script variable $-tokens to specify the full path name $F and its date taken property ${Picture date}, using single and double quotes to guard against spaces. You don't need to understand what this command does, just copy/paste it into xplorer² script wizard and hit Preview button to see what it does.

If instead of a date you see "last month" make sure you turn off the friendly dates option.

batch image date conversion
Figure 1. Batch template command for touching picture dates

Summary: How to change picture dates en mass:

The same trick can be used to change dates of video files (MP4 etc). The only difference is that instead of {picture date} we must use {media created}, as video files store their creation date in a different property column. So for video files you execute this script command template:

powershell -command "& {(get-item '$F').LastWriteTime = get-date '${media created}'}"

ps. Happy 6th birthday Achillea!

Post a comment on this topic »

Share |

©2002-2018 ZABKAT LTD, all rights reserved | Privacy policy | Sitemap