所以我注意到 %time% 变量在批处理文件的日志中不准确,如下所示。输出包含在代码下方...它在进入 for 循环时获取当前时间,但不会在运行时更新它。这些是大型 zip 文件,有时需要几分钟才能解压缩每个文件。有人知道这里发生了什么吗?
代码:
@echo off
setlocal EnableDelayedExpansion
for /f "tokens=1-26 delims=/:. " %%a in ('echo %date% %time%') do set today=%%d%%b%%c
echo %date% %time% process start >> h:\logfiles\unzip\%today%.log
:BANK1
set bank=BANK1
call:process BANK1LOCKBOX.lbx.6*.zip
call:process BANK1LOCKBOX.lbx.3*.zip
:BANK2
set bank=BANK2
call:process BANK2LOCKBOX.A*.zip PASSWORD1
call:process BANK2LOCKBOX.R*.zip PASSWORD2
echo %date% %time% process complete >> h:\logfiles\unzip\%today%.log
goto:eof
:process
set thisfile=%1
set pword=-y
if not [%2] equ [] set pword=-p%2 -y
if exist f:\banks\%bank%\zipped\%thisfile% (
echo %time% %thisfile% begin >> h:\logfiles\unzip\%today%.log
for /f "tokens=1-2 delims=;" %%a in ('dir /b f:\banks\%bank%\zipped\%thisfile%') do (
echo %time% %%a start >> h:\logfiles\unzip\%today%.log
7z x f:\banks\%bank%\zipped\%%a -of:\banks\%bank%\* %pword%
if %errorlevel%==0 (
move /y f:\banks\%bank%\zipped\%%a f:\banks\%bank%\processed\
echo %time% %%a complete >> h:\logfiles\unzip\%today%.log
)
)
if exist f:\banks\%bank%\zipped\%thisfile% (
move /y f:\banks\%bank%\zipped\%thisfile% f:\banks\%bank%\unprocessed\
echo %time% %thisfile% failed >> h:\logfiles\unzip\%today%.log
)
echo %time% %thisfile% end >> h:\logfiles\unzip\%today%.log
)
日志如下所示:
Tue 07/02/2013 10:40:55.70 process start
10:40:55.72 BANK1LOCKBOX.lbx.6*.zip begin
10:40:55.72 BANK1LOCKBOX.lbx.60.zip start
10:40:55.72 BANK1LOCKBOX.lbx.60.zip complete
10:40:55.72 BANK1LOCKBOX.lbx.64.zip start
10:40:55.72 BANK1LOCKBOX.lbx.64.zip complete
10:40:55.72 BANK1LOCKBOX.lbx.6*.zip end
10:41:14.02 BANK1LOCKBOX.lbx.3*.zip begin
10:41:14.02 BANK1LOCKBOX.lbx.391.zip start
10:41:14.02 BANK1LOCKBOX.lbx.391.zip complete
10:41:14.02 BANK1LOCKBOX.lbx.343.zip start
10:41:14.02 BANK1LOCKBOX.lbx.343.zip complete
10:41:14.02 BANK1LOCKBOX.lbx.3*.zip end
10:42:48.28 BANK2LOCKBOX.A*.zip begin
10:42:48.28 BANK2LOCKBOX.A_0_1.zip start
10:42:48.28 BANK2LOCKBOX.A_0_1.zip complete
10:42:48.28 BANK2LOCKBOX.A_6_1.zip start
10:42:48.28 BANK2LOCKBOX.A_6_1.zip complete
10:42:48.28 BANK2LOCKBOX.A_2_1.zip start
10:42:48.28 BANK2LOCKBOX.A_2_1.zip complete
10:42:48.28 BANK2LOCKBOX.A*.zip end
10:44:42.33 BANK2LOCKBOX.R*.zip begin
10:44:42.33 BANK2LOCKBOX.R_1359_1.zip start
10:44:42.33 BANK2LOCKBOX.R_1359_1.zip complete
10:44:42.33 BANK2LOCKBOX.R_1365_1.zip start
10:44:42.33 BANK2LOCKBOX.R_1365_1.zip complete
10:44:42.33 BANK2LOCKBOX.R_1371_1.zip start
10:44:42.33 BANK2LOCKBOX.R_1371_1.zip complete
10:44:42.33 BANK2LOCKBOX.R*.zip end
Tue 07/02/2013 10:45:25.91 process complete