2

Hey I have this little batch file that is supposed to compare the timestamps of two files and return errorvlvl 0 or 2 depending on whether the source file is newer or not (it gets passed the 2 filenames as parameters) but I dont think the gtr is workig right for timestamps.. I works some of the time and not others...how would I parse the timespamps as integers to compare them. btw the variables source and dest look like this (i echoed them to see)
05/06/2012 18:46

 REM I use the t prefix here to expand the file location parameters passed in, i       into  date/time values
set source=%~t1
echo %dest%
set dest=%~t2
echo %source%

if "%source%" gtr "%dest%" goto overwrite
exit /b 0 
:overwrite
REM if the source file is newer compare.bat will return an errorlevel of 2, this will    then be used in an if statement in the file that called compare.bat to go ahead and overwrite the older file
exit /b 2 

Thanks in advance for any advice!! :)

Guye Incognito
  • 2,726
  • 6
  • 38
  • 72
  • possible duplicate of [How can I check the time stamp creation of a file in a Windows batch script?](http://stackoverflow.com/questions/6840156/how-can-i-check-the-time-stamp-creation-of-a-file-in-a-windows-batch-script) – George Stocker Jun 06 '12 at 00:32

1 Answers1

2

ok. I got it .. i think!

set compsource= %dest:~6,4%%dest:~3,2%%dest:~0,2%%dest:~6,4%%dest:~11,2%%dest:~14,2%
Bali C
  • 30,582
  • 35
  • 123
  • 152
Guye Incognito
  • 2,726
  • 6
  • 38
  • 72
  • +1, I do believe you did get it :-) I think you can simplify a bit to `set compsource= %dest:~6,4%%dest:~3,2%%dest:~0,2%%dest:~11%`. Note that the format of %~t1 can change depending on the locale of the computer. – dbenham Jun 05 '12 at 21:59