2012-06-05 130 views
2

嘿,我有这个小的批处理文件,应该比较两个文件的时间戳,并返回errorvlvl 0或2,这取决于源文件是否更新或不(它获取通过2个文件名作为参数)但我不认为gtr是时间戳的正确工作。我工作了一些时间,而不是其他人...我如何解析时间戳作为整数来比较它们。 者均基于变量源和目标看起来像这样(我赞同他们看到)
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 

预先感谢任何建议! :)

+0

可能重复[如何检查Windows批处理脚本中的文件的时间戳创建?](http://stackoverflow.com/questions/6840156/how-can-i-check-the -h-windows-batch-script- –

回答

2

好的。我明白了......我想!

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

+1,我确信你确实得到了它:-)我认为你可以简化一点到'set compsource =% DEST:〜6,4 %% DEST:〜3,2 %% DEST:〜0,2 %% DEST:〜11%'。请注意,%〜t1的格式可能会根据计算机的区域设置而改变。 – dbenham