Copyright © 2003-2010 by Prof. Timo Salmi  
Last modified Sat 17-Apr-2010 15:15:36

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.

7} How can I test if two files agree in size and datetime stamp?

This one is rather simple given the features of XP CMD.EXE.
  @echo off
  :: Get the filenames (one way or the other)
  set file1_=%~1
  set file2_=%~2
  rem set file1_=c:\_d\bas\batfaq2.bat
  rem set file2_=c:\_f\xtools\xptd.cmd
  :: Check for existence
  for %%f in ("%file1_%" "%file2_%") do (
    if not exist %%f (
      echo File %%f not found
      goto :EOF))
  :: Get the filesizes and the datestamps
  for %%f in ("%file1_%") do set size1_=%%~zf
  for %%f in ("%file2_%") do set size2_=%%~zf
  for %%f in ("%file1_%") do set date1_=%%~tf
  for %%f in ("%file2_%") do set date2_=%%~tf
  :: Also get the full file names (optional)
  for %%f in ("%file1_%") do set file1_=%%~ff
  for %%f in ("%file2_%") do set file2_=%%~ff
  :: Demonstrate what we've got so far
  echo %date1_% "%file1_%" %size1_%
  echo %date2_% "%file2_%" %size2_%
  :: Do the comparison
  set same_=false
  if "%size1_%"=="%size2_%" if "%date1_%"=="%date2_%" set same_=true
  :: Display the results

  if /i "%same_%"=="true" (
    echo The file dates and sizes agree
    ) else (
    echo The file dates and/or sizes do not agree)
  goto :EOF

The output might be e.g.
  C:\_D\TEST>cmdfaq "KOE 2.CMD" "VBSFAQ2.VBS"
  12.09.2004 09:28 "C:\_D\TEST\KOE 2.CMD" 817
  06.10.2007 09:28 "C:\_D\TEST\VBSFAQ2.VBS" 4084
  The file dates and/or sizes do not agree

Also see Item #62.