Click here to Skip to main content
15,392,261 members
Articles / Desktop Programming / MFC
Posted 2 Aug 2008


52 bookmarked

JPGDateChanger - Tool to Restore Last Modified Date for JPG Files

Rate me:
Please Sign up or sign in to vote.
4.96/5 (21 votes)
8 Nov 2012CPOL5 min read
JPGDateChanger is a tool that changes last modified date to the one stored in EXIF data



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.


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 | ;-)


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:

	CFile::SetStatus(strName, fs);
catch (CException* e)
	// 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.


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


  • 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


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


About the Author

Damir Valiulin
Software Developer
Canada Canada
No Biography provided

Comments and Discussions

QuestionHow Do I Drag and Drop Here? Pin
Member 147088946-Jan-20 19:05
MemberMember 147088946-Jan-20 19:05 
QuestionAbsolutely fantastic! Pin
Member 1378361116-Apr-18 23:05
MemberMember 1378361116-Apr-18 23:05 
PraiseExactly what I was searching for! Pin
Member 1375524730-Mar-18 10:01
MemberMember 1375524730-Mar-18 10:01 
GeneralPerfect Pin
Member 118949558-Aug-15 1:29
MemberMember 118949558-Aug-15 1:29 
QuestionAMAZING Pin
Member 115959299-Apr-15 22:00
MemberMember 115959299-Apr-15 22:00 
GeneralMy vote of 5 Pin
Member 1152973717-Mar-15 4:39
MemberMember 1152973717-Mar-15 4:39 
BugThe parameter is incorrect. Pin
Member 1074636513-Apr-14 14:46
MemberMember 1074636513-Apr-14 14:46 
GeneralRe: The parameter is incorrect. Pin
Damir Valiulin14-Apr-14 6:03
MemberDamir Valiulin14-Apr-14 6:03 
GeneralRe: The parameter is incorrect. Pin
DemonCamber X (XDemonCamberX)9-Jul-14 9:08
MemberDemonCamber X (XDemonCamberX)9-Jul-14 9:08 
GeneralRe: The parameter is incorrect. Pin
DemonCamber X (XDemonCamberX)9-Jul-14 9:25
MemberDemonCamber X (XDemonCamberX)9-Jul-14 9:25 
QuestionRemove "jpg" file filter or allow "jps" files Pin
peterjwhite27-Jan-13 18:25
Memberpeterjwhite27-Jan-13 18:25 
AnswerRe: Remove "jpg" file filter or allow "jps" files Pin
Damir Valiulin14-Feb-13 4:40
MemberDamir Valiulin14-Feb-13 4:40 
GeneralRe: Remove "jpg" file filter or allow "jps" files Pin
peterjwhite14-Feb-13 13:45
Memberpeterjwhite14-Feb-13 13:45 
QuestionThanks! Now it works perfectly even for Unicode file names Pin
Vladimir Dvorak15-Nov-12 21:44
MemberVladimir Dvorak15-Nov-12 21:44 
GeneralMy vote of 5 Pin
gndnet9-Nov-12 23:46
Membergndnet9-Nov-12 23:46 
QuestionWould it be possible to extend to Unicode characters? Pin
Vladimir Dvorak30-Oct-12 7:59
MemberVladimir Dvorak30-Oct-12 7:59 
AnswerRe: Would it be possible to extend to Unicode characters? Pin
Damir Valiulin7-Nov-12 8:01
MemberDamir Valiulin7-Nov-12 8:01 
QuestionThank you! Pin
Member 86217744-Feb-12 19:08
MemberMember 86217744-Feb-12 19:08 
QuestionThanks Pin
jolindien22-Jan-12 1:55
Memberjolindien22-Jan-12 1:55 
GeneralThanks! Pin
Samuel Dutton3-May-11 9:19
MemberSamuel Dutton3-May-11 9:19 
GeneralThank You - Just Thank You So Much For Such An Intelligent Simple Program!!! Pin
Member 78044681-Apr-11 1:09
MemberMember 78044681-Apr-11 1:09 
GeneralRe: Thank You - Just Thank You So Much For Such An Intelligent Simple Program!!! Pin
Damir Valiulin1-Apr-11 3:24
MemberDamir Valiulin1-Apr-11 3:24 
GeneralDate Taken = Date Modified Pin
biskidos27-Jan-11 14:42
Memberbiskidos27-Jan-11 14:42 
GeneralRe: Date Taken = Date Modified Pin
Damir Valiulin29-Jan-11 12:37
MemberDamir Valiulin29-Jan-11 12:37 
GeneralRe: Date Taken = Date Modified Pin
Ja Opet1-May-13 21:31
MemberJa Opet1-May-13 21:31 

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

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