Click here to Skip to main content
6,822,613 members and growing! (19,756 online)
Email Password   helpLost your password?
Web Development » Applications & Tools » Tools with source code License: The Code Project Open License (CPOL)

JPGDateChanger - Tool to Restore Last Modified Date for JPG Files

By Damir Valiulin

JPGDateChanger is a tool that changes last modified date to the one stored in EXIF data
C++/CLI, VC6, VC7, VC7.1, VC8.0, Windows, Visual-Studio, MFC
Revision:5 (See All)
Posted:2 Aug 2008
Updated:4 Jan 2010
Views:17,090
Bookmarked:23 times
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
7 votes for this article.
Popularity: 3.84 Rating: 4.55 out of 5

1

2
1 vote, 14.3%
3
1 vote, 14.3%
4
5 votes, 71.4%
5
jpgdatechanger.jpg

Introduction

JPGDateChanger is a tool that changes last modified 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.

After screwing up the dates on some pictures for the N-th 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. ;-)

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 Undo button to revert dates on the last batch of files that you dropped. You can also view detailed log of all processed files.

About the Code

For details on reading EXIF from JPG files, see Davide Pizzolato's article CExif. To change the date, I simply use MFC's CFile::GetStatus and CFile::SetStatus functions:

CFileStatus fs;
if (CFile::GetStatus(fname, fs))
{
   CTime t_new (d_yyyy, d_mm, d_dd, t_hh, t_mm, t_ss);
   fs.m_mtime = t_new;
   CFile::SetStatus(fname, fs);
}

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 the latest update I also added message pumping to keep interface responsive when processing thousands of files. Multi-threading is usually preferred method for this, but I thought it was overkill for a simple program like this.

Links

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

History

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

About the Author

Damir Valiulin


Member

Occupation: Software Developer
Location: Canada Canada

Other popular Applications & Tools articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 25 of 28 (Total in Forum: 28) (Refresh)FirstPrevNext
Questiondate modified = date created Pinmembertravelgirl8:14 20 Jan '10  
AnswerRe: date modified = date created PinmemberDamir Valiulin9:08 20 Jan '10  
GeneralRe: date modified = date created Pinmembertravelgirl9:15 20 Jan '10  
GeneralRe: date modified = date created PinmemberDamir Valiulin10:55 20 Jan '10  
GeneralRe: date modified = date created Pinmembertravelgirl14:22 20 Jan '10  
GeneralRe: date modified = date created PinmemberDamir Valiulin19:22 20 Jan '10  
GeneralGreat app - thanks for sharing Pinmembersj117218:15 21 Nov '09  
GeneralVery useful app, but I fixed a little problem [modified] Pinmemberganber5:25 17 Aug '09  
GeneralRe: Very useful app, but I fixed a little problem PinmemberDamir Valiulin5:20 18 Aug '09  
GeneralFantastic Program PinmemberEddieBook18:27 20 Jul '09  
GeneralRe: Fantastic Program PinmemberDamir Valiulin4:56 21 Jul '09  
GeneralAutorotate utility doesn't alter modify date; anyway, use "Date Picture Taken" Pinmemberbruce_bush_nj16:20 13 May '09  
GeneralRe: Autorotate utility doesn't alter modify date; anyway, use "Date Picture Taken" PinmemberDamir Valiulin6:00 15 May '09  
GeneralBrilliant, but there may be a problem... Pinmemberfliccle10:32 30 Jan '09  
GeneralRe: Brilliant, but there may be a problem... PinmemberDamir Valiulin13:52 31 Jan '09  
GeneralRe: Brilliant, but there may be a problem... Pinmemberfliccle4:13 2 Feb '09  
GeneralRe: Brilliant, but there may be a problem... Pinmembersupercat97:28 27 Jul '09  
GeneralRe: Brilliant, but there may be a problem... Pinmemberfliccle1:46 20 Aug '09  
GeneralGreat software Pinmemberroadbug14:26 14 Sep '08  
GeneralHow many files in one go? PinmemberCurt Henning de Thurah13:23 12 Aug '08  
GeneralRe: How many files in one go? PinmemberDamir Valiulin19:56 15 Aug '08  
GeneralHow about Date Created? PinmemberKent K13:14 5 Aug '08  
GeneralRe: How about Date Created? PinmemberDamir Valiulin15:04 5 Aug '08  
GeneralRe: How about Date Created? PinmemberKent K5:59 6 Aug '08  
GeneralRe: How about Date Created? PinmemberDamir Valiulin6:58 7 Aug '08  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

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

PermaLink | Privacy | Terms of Use
Last Updated: 4 Jan 2010
Editor: Sean Ewington
Copyright 2008 by Damir Valiulin
Everything else Copyright © CodeProject, 1999-2010
Web18 | Advertise on the Code Project