我创建了一个批处理文件来检查第一行中的日期和最后一行中的EOF标志。如果满足要求,则继续。 Bellow是批处理文件。
@ECHO OFF
SET LOGFILE_DATE=%DATE:~4,2%.%DATE:~7,2%.%DATE:~10,4%
SET LOGFILE_TIME=%TIME:~0,2%.%TIME:~3,2%
SET LOGFILE="C:\N-able\Projects\AML\NDB Bank\devinda\AML_Data_Auto-%LOGFILE_DATE%-%LOGFILE_TIME%.log"
call :Logit >> %LOGFILE%
exit /b 0
:Logit
::
set "firstLine"
for /f "tokens=*" %%A in (C:\N-able\Projects\AML\NDB Bank\devinda\AML_handshake.txt) do (
If not defined firstLine set "firstLine=%%A"
set Lastline=%%A)
)
set "date=%firstLine:~9,8%"
REM *** FIRST CHECK ***
if "EOF" NEQ "%Lastline%" goto fail
REM *** SECOND CHECK ***
set day=-1
echo >"%temp%\%~n0.vbs" s=DateAdd("d",%day%,now) : d=weekday(s)
echo>>"%temp%\%~n0.vbs" WScript.Echo year(s)^& right(100+month(s),2)^& right(100+day(s),2)
for /f %%a in ('cscript /nologo "%temp%\%~n0.vbs"') do set "result=%%a"
del "%temp%\%~n0.vbs"
set "YYYY=%result:~0,4%"
set "MM=%result:~4,2%"
set "DD=%result:~6,2%"
set "data=%yyyy%-%mm%-%dd%"
if "%data%" NEQ "%date%" goto fail
exit /b
goto prog
:prog
...Some Codes...
:fail
echo Initial Check Failed, Process Terminated
而bellow是文本文件。
AML.DATA|2016-06-16
PORT_DATA|560538
NDB_AML_AA|43063
NDB_AML_LD|12878
NDB_AML_REPO|496
NDB_AML_TRAN|84596
NDB_AML_JOINT_AC|219873
NDB_AML_CUS_REL_PRTY|43
NDB_AML_BICCODE|108292
CUSTOMER_MASTER|684124
CATEGORY.MASTER|3288
DEPT.MASTER|2527
COUNTRY.MASTER|251
CUSTOMER.STATUS.MASTER|26
INDUSTRY.MASTER|65
JOB.TITLE.MASTER|22
COMPANY.MASTER|121
TRANSACTION.MASTER|3133
RELATION.MASTER|56
NDB_AML_TBILL_TBOND|2845
EOF
即使日期和EOF标志已满足,它仍然会转到:fail
。
C:\N-able\Projects\AML\NDB Bank\devinda>set "firstLine"
C:\N-able\Projects\AML\NDB Bank\devinda>for /F "tokens=*" %A in (C:\N-able\Projects\AML\NDB Bank\devinda\AML_handshake.txt) do (
If not defined firstLine set "firstLine=%A"
set Lastline=%A
)
C:\N-able\Projects\AML\NDB Bank\devinda>set "date=~9,8"
C:\N-able\Projects\AML\NDB Bank\devinda>REM *** FIRST CHECK ***
C:\N-able\Projects\AML\NDB Bank\devinda>if "EOF" NEQ "" goto fail
C:\N-able\Projects\AML\NDB Bank\devinda>echo Initial Check Failed, Process Terminated
Initial Check Failed, Process Terminated
我需要一些帮助来解决它。
答案 0 :(得分:1)
set "date=%firstLine:~9,8%"
这太短了,它只给你YYYY-MM-
,但你把它与YYYY-MM-DD
进行比较,所以if
永远不会成真。将其更改为:
set "date=%firstLine:~9,10%"
... 请不要将%date%
用作变量名称 - 它是系统变量;更改它可能会导致代码的其他部分出现不可预测的行为。选择另一个变量名称。