嘿,我有这个小批处理文件,它应该比较两个文件的时间戳并返回 errorvlvl 0 或 2,具体取决于源文件是否较新(它传递 2 个文件名作为参数),但我不认为gtr 对于时间戳来说是正确的。我有时工作,而不是其他时间...我如何将时间戳解析为整数来比较它们。
顺便说一句,变量 source 和 dest 看起来像这样(我回显它们以查看)
2012年5月6日 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
预先感谢您的任何建议! :)
最佳答案
好的。我明白了..我想!
set compsource= %dest:~6,4%%dest:~3,2%%dest:~0,2%%dest:~6,4%%dest:~11,2%%dest:~14,2%
关于batch-file - 批处理日期时间戳比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10902272/