This page is edited from the 1cmdfaq.txt faq-file contained in
command line interface (CLI) collection. That zipped file has much
additional material, including a number of detached .cmd script
files. It is recommended that you also get the zipped version as a
Please see "The Description and
the Index page
" for the conditions of usage and other such
134} How do I advance the dates of my certain JPG files by one year?
You'll need a touch utility or a port for the script below.
@echo off & setlocal enableextensions enabledelayedexpansion
rem Note, assumes date format DD.MM.YYYY hh:mm
rem E.g. 21.02.2006 08:14
if "%~1"=="" (
echo Usage: %~0 [Filename]
:: Check that the file(s) to be restamped exist
if not exist "%~1" (
echo File^(s^) "%~1" not found
:: Store the potential time zone information, and make a note
if defined tz (
@rem the current timezone TZ is %TZ%
:: Get the old stamps and display the commands for changing them
for %%f in ("%~1") do (
set /a fileyear_new=!fileyear! + 1
touch -c -f !filemm!!filedd!!filehour!!filemin!!fileyear_new! !filename!
:: Restore the original timezone information
if defined tz echo
endlocal & goto :EOF
The output might be e.g.
@rem the current timezone TZ is Europe/Helsinki
touch -c -f 011513242007 C:\_H\PHOTO\HME2006A\66011507.JPG
touch -c -f 020213322007 C:\_H\PHOTO\HME2006A\66020201.JPG
Remove the safety echo
s when you want to do it for real.
The above example was for exactly a one year increment. For generic
changes for any number of days from now on, or back, take the needed
additional cues from item #31
The is a slight catch. The method zeroes the seconds part, since XP
will not display them. E.g. a VBS-aided script, such as my included
FileInfo Visual Basic
Script" would be needed to get also the seconds in a file's datestamp.
For a robust VBS-aided single-file script method for getting a file's
date/time stamp see GETFDATE.CMD
If you wish to be very orthodox, check that the touch you use knows
how to handle the very rare case of Feb 29 correctly.