批日期时间戳比较

时间:2012-06-05 17:48:37

标签: batch-file timestamp compare

嘿,我有这个小批处理文件应该比较两个文件的时间戳并返回errorvlvl 0或2,具体取决于源文件是否更新(它将2个文件名作为参数传递)但我不认为gtr对于时间戳是正确的。我在某些时候工作而不是其他人...我如何将时间差解析成整数来比较它们。 顺便说一下变量source和dest看起来像这样(我回应他们看) 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 

提前感谢任何建议!! :)

1 个答案:

答案 0 :(得分:2)

确定。我明白了......我想!

set compsource= %dest:~6,4%%dest:~3,2%%dest:~0,2%%dest:~6,4%%dest:~11,2%%dest:~14,2%