Click here to Skip to main content
Click here to Skip to main content

JPGDateChanger - Tool to Restore Last Modified Date for JPG Files

, 8 Nov 2012 CPOL
Rate this:
Please Sign up or sign in to vote.
JPGDateChanger is a tool that changes last modified date to the one stored in EXIF data

JPGDateChanger/jpgdatechanger.jpg

Introduction

JPGDateChanger is a tool that changes file date of a JPG file to match the date extracted from Date Taken field in the file's EXIF tag.

Background

Often after transferring images from my digital camera, I quickly go through them and fix the orientation on pictures taken in portrait mode. On my XP machine, I simply use the built in Windows Picture and Fax Viewer to do the job. On my Vista machine, this program was replaced with Windows Photo Gallery. The new 'feature' of Vista's replacement is that clicking on Rotate button sets the "Date Modified" to current time. I find this behaviour really annoying, since I usually sort my pictures in the folder by date.

Another feature of Windows I found frustrating is when it stamps all the files with current date and time instead of original date if transferring images via USB cable instead of copying off media card directly.

After screwing up the dates on some pictures for the Nth time (being forgetful), I tried to find a tool on the Internet that would change the date back by extracting it from EXIF tag. Unfortunately I found only some all-in-one utilities, all bloated and all shareware.

Well, it shouldn't be too hard to write one myself, I thought. Turned out it was dead simple. Immediately on CodeProject, I found Davide Pizzolato's article CExif, and in 15 minutes, after modifying his example, I had a working program! The other several hours went into polishing its look and adding features. Wink | ;-)

Usage

To use the tool, simply drop JPG files on the main window and their dates will be automatically updated. The files must have extension JPG or JPEG. If some image files don't have EXIF tag, or the date stored in the EXIF is the same as last modified date, no action will be taken on those files.

I added "Keep Window on Top" option for convenience and this preference is stored in the Windows Registry.

You can also drag and drop folders and the program will process all the files in those folders and subfolders (if this option is checked).

If you suddenly realize that you just made a mistake, there is an Undo button to revert dates on the last batch of files that you dropped. You can also view a detailed log of all processed files.

About the Code

For details on reading EXIF from JPG files with C++, see Davide Pizzolato's article CExif.

Actually, while trying to fix a bug in CExif for ver 1.4, I had to learn a great deal about EXIF structure - more than I ever wanted to. The document that I found most helpful can be found here. Written by TsuruZoh Tachibanaya, it cuts straight to the chase and has lots of easy to follow tables.

To change the date, I simply use MFC's CFile::GetStatus and CFile::SetStatus functions. One thing that is omitted in MSDN documentation about CFile::SetStatus is that it throws an exception if it fails to set a status for any reason. So be sure to wrap SetStatus call with a try/catch block:

try	
{	
	CFile::SetStatus(strName, fs);
}
catch (CException* e)
{
	e->Delete();
	// You can use ::GetLastError() to get Windows error code
}

Another interesting challenge for me was trying to make the project to build in both VC6 and VS2008. The challenging part was the manifest file in resources for XP themes. The project was originally built in VC6, but then I converted it to VS2008. Any modification to resources in VS2008 IDE would result in it writing RT_MANIFEST into .rc file instead of the number 24. If you were then to open such a project in VC6 and build, the visual styles would not be applied because RT_MANIFEST is not defined there and resource compiler treats it as a literal string “RT_MANIFEST”.

The solution was to create a header file with RT_MANIFEST defined in it and add it to resource includes. Now you can edit resource in either IDE and it will still build with visual styles in VC6 and VS2008.

In one of the updates (1.3), I also added message pumping to keep interface responsive when processing thousands of files. Multi-threading is usually a preferred method for this, but I thought it was overkill for a simple program like this.

UPDATE 2012-11-08: In version 1.5 I converted the project to Unicode which was not such a hard task as I initially thought it was. Now the program is able to handle files with international characters in their names  As a result though I had to drop VC6 support since the project would not compile in it. To read and write log and undo file in Unicode I used CStdioFileEx a nice extension class written by David Pritchard.

Links

Here are all the links to other people's work that I used to create this tool:

History

  • 2012-11-08, v1.5
    • Converted project to Unicode to handle international characters in file names.
  • 2010-05-08, v1.4
    • Fixed bug in CExif that would not extract EXIF from certain JPG files 
  • 2010-01-04, v1.3
    • Fixed folder processing bug (Thanks to Bernhard)
    • Fixed initial combo selection bug – it was empty (Bernhard)
    • Fixed EXIF date tag checking (Thanks to sj1172)
    • Added error checking when modifying date. The program will no longer abort with error message.
    • Added status update during lengthy operations. The interface is more responsive now when processing lots of files. (Suggestion by sj1172)
    • Added ability to view log file after processing is complete
    • Changed reference to Hans Dietrich’s article from XColorStatic to XHTMLStatic – didn’t notice this mistake since the original posting
  • 2009-07-23, v1.2
    • Added ability to recognize and process folders and subfolders
    • Added “Process subfolders” checkbox
    • Added Undo functionality to be able to undo last batch
    • Added VS2008 solution to the project source
  • 2008-08-07, v1.1
    • Added combobox that allows user to choose which date to correct: Date Modified, Date Created, or both
  • 2008-08-02, v1.0
    • Initial posting to CodeProject

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Damir Valiulin
Software Developer
Canada Canada
No Biography provided

Comments and Discussions

 
BugThe parameter is incorrect. PinmemberMember 1074636513-Apr-14 14:46 
GeneralRe: The parameter is incorrect. PinmemberDamir Valiulin14-Apr-14 6:03 
GeneralRe: The parameter is incorrect. [modified] PinmemberDemonCamber X (XDemonCamberX)9-Jul-14 9:08 
GeneralRe: The parameter is incorrect. PinmemberDemonCamber X (XDemonCamberX)9-Jul-14 9:25 
QuestionRemove "jpg" file filter or allow "jps" files Pinmemberpeterjwhite27-Jan-13 18:25 
AnswerRe: Remove "jpg" file filter or allow "jps" files PinmemberDamir Valiulin14-Feb-13 4:40 
GeneralRe: Remove "jpg" file filter or allow "jps" files Pinmemberpeterjwhite14-Feb-13 13:45 
QuestionThanks! Now it works perfectly even for Unicode file names PinmemberVladimir Dvorak15-Nov-12 21:44 
GeneralMy vote of 5 Pinmembergndnet9-Nov-12 23:46 
QuestionWould it be possible to extend to Unicode characters? PinmemberVladimir Dvorak30-Oct-12 7:59 
AnswerRe: Would it be possible to extend to Unicode characters? PinmemberDamir Valiulin7-Nov-12 8:01 
QuestionThank you! PinmemberMember 86217744-Feb-12 19:08 
QuestionThanks Pinmemberjolindien22-Jan-12 1:55 
GeneralThanks! PinmemberMember 78935943-May-11 9:19 
GeneralThank You - Just Thank You So Much For Such An Intelligent Simple Program!!! PinmemberMember 78044681-Apr-11 1:09 
GeneralRe: Thank You - Just Thank You So Much For Such An Intelligent Simple Program!!! PinmemberDamir Valiulin1-Apr-11 3:24 
GeneralDate Taken = Date Modified Pinmemberbiskidos27-Jan-11 14:42 
GeneralRe: Date Taken = Date Modified PinmemberDamir Valiulin29-Jan-11 12:37 
GeneralRe: Date Taken = Date Modified PinmemberJa Opet1-May-13 21:31 
GeneralRe: Date Taken = Date Modified PinmemberMember 1007796526-May-13 18:13 
GeneralXNView PinmemberTomy210511-May-10 1:12 
GeneralRe: XNView PinmemberDamir Valiulin12-May-10 10:34 
Questionnot detecting EXIF PinmemberChris Eckl7-Mar-10 6:14 
AnswerRe: not detecting EXIF PinmemberDamir Valiulin7-Mar-10 17:35 
GeneralFantastic!!! PinmemberKotFrot15-Feb-10 8:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.141015.1 | Last Updated 9 Nov 2012
Article Copyright 2008 by Damir Valiulin
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid