我有一个将文件戳与脚本执行时间戳进行比较的代码。如果值不同,它会起作用,但是当值相同时,代码仍然不会跳出循环。我认为这背后的原因是脚本开头的语句 setlocal enableDelayedExpansion 。
该代码正确打印了 filesstamp 和 datestamp 的值,但是 if 逻辑无法正常工作。
@ECHO off
setlocal EnableDelayedExpansion
ECHO !fileTimemod!>x&FOR %%? IN (x) DO SET /A strlength=%%~z? - 2&del x
echo filetimelength !strlength!
IF !strlength! EQU 1 (
SET fileTimemod=0!fileTimemod!
echo fileTimemod !fileTimemod!
)
set FileM=!filestamp:~0,2!
set FileD=!filestamp:~3,2!
set FileY=!filestamp:~6,4!
set filestamp=!FileY!!FileM!!FileD!!final!
echo datestamp !datestamp!
echo filestamp !filestamp!
set newTimestamp=!filestamp!
if "!datestamp!" gtr "!filestamp!" (
echo The file is older than the script execution time.
) else (
echo Read the new file
)
**日志** **日期戳 201310071449 文件戳 201310071435** 该文件早于脚本执行时间。 24 延迟 计数器值为 1 检查文件是否存在于目录中 2013 年 10 月 7 日下午 02:49 文件分钟 49 02 文件AMPM PM 2 文件时间长度 1 文件时间模块 2 结果 14 最终1449 **日期戳 201310071449 文件戳 201310071449** 该文件早于脚本执行时间。 24 延迟
欢迎提出建议。
提前致谢!