<http://www.netikka.net/tsneti/info/tscmd134.htm>
Copyright © 2003-2010 by Prof. Timo Salmi  
Last modified Tue 6-Apr-2010 17:57:10

 
Assorted NT/2000/XP/.. CMD.EXE Script Tricks
From the html version of the tscmd.zip 1cmdfaq.txt file
To the Description and the Index
 

This page is edited from the 1cmdfaq.txt faq-file contained in my tscmd.zip 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 companion.

Please see "The Description and the Index page" for the conditions of usage and other such information.

  

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

  ::
  :: Usage

  if "%~1"=="" (
    echo Usage: %~0 [Filename]
    goto :EOF
    )
  :: Check that the file(s) to be restamped exist
  if not exist "%~1" (
    echo File^(s^) "%~1" not found
    goto :EOF
    )
  ::
  :: Store the potential time zone information, and make a note

  if defined tz (
    echo @rem the current timezone TZ is %TZ%
    echo set TZ=
    )
  set storetz=%tz%
  set tz=
  ::
  :: Get the old stamps and display the commands for changing them

  for %%f in ("%~1") do (
    set filename=%%~dpnxf
    set filestamp=%%~tf
    set filedd=!filestamp:~0,2!
    set filemm=!filestamp:~3,2!
    set fileyear=!filestamp:~6,4!
    set filehour=!filestamp:~11,2!
    set filemin=!filestamp:~14,2!
    ::
    set /a fileyear_new=!fileyear! + 1
    echo touch -c -f !filemm!!filedd!!filehour!!filemin!!fileyear_new! !filename!
    )
  ::
  :: Restore the original timezone information

  set tz=%storetz%
  if defined tz echo set TZ=%tz%
  endlocal & goto :EOF

The output might be e.g.
  C:\_D\TEST>cmdfaq C:\_H\PHOTO\HME2006A\*.JPG
  @rem the current timezone TZ is Europe/Helsinki
  set TZ=
  touch -c -f 011513242007 C:\_H\PHOTO\HME2006A\66011507.JPG
  touch -c -f 020213322007 C:\_H\PHOTO\HME2006A\66020201.JPG
  set TZ=Europe/Helsinki
Remove the safety echos 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.VBS 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.