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. https://www.codeproject.com/script/Forums/Images/smiley_wink.gif
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::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:
catch (CException* e)
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 “
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
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