2016-06-20 132 views
1

我仍然在學習語言,所以請放縱。問題與我的批處理腳本

在下面的代碼中與我的START變量相關的條件從不觸發,我找不到原因。如果當前行以「80 /」開頭,並且前面的行以分號和空格開始,那麼該部分應該執行。可能是一個synthax錯誤或一些這樣的。任何幫助將不勝感激。

@ECHO OFF 
SETLOCAL DISABLEDELAYEDEXPANSION 

>"%~dpn1_2.txt" (
    FOR /F "tokens=1* delims=]" %%j in ('find /V /N "" %1') DO (
     SET "currentLine=%%k" 
     SETLOCAL ENABLEDELAYEDEXPANSION 
     IF "!currentLine:~0,2!"=="; " (
      SET START=1 
     ) ELSE IF "!currentLine:~0,3!"=="80/" (
      IF "!START!"=="1" (
       SET "currentLine=!currentLine:~0,2!!currentLine:~3,5! !currentLine:~18!" 
       SET START= 
      ) ELSE (
       SET string=!currentLine:~0,2!!currentLine:~3,4! 
       FIND "!string!" labels.txt > nul 
       IF !errorlevel! EQU 0 (
        SET "currentLine=!currentLine:~0,2!!currentLine:~3,5! !currentLine:~18!" 
       ) ELSE (
        SET "currentLine=   !currentLine:~18!" 
       ) 
      ) 
     ) 
     ECHO(!currentline! 
     ENDLOCAL 
    ) 
) 
+0

有沒有'批量 – SomethingDark

+1

@SomethingDark ELSE IF','其他if'不做工精細... – aschipfl

+0

這是誤導。 – SomethingDark

回答

0
@ECHO OFF 
SETLOCAL DISABLEDELAYEDEXPANSION 

>"%~dpn1_2.txt" (
    FOR /F "tokens=1* delims=]" %%j in ('find /V /N "" %1') DO (
    SET "currentLine=%%k" 
    SETLOCAL ENABLEDELAYEDEXPANSION 
    IF "!currentLine:~0,3!"=="80/" (
     IF "!previousLine:~0,2!"=="; " (
     SET "currentLine=!currentLine:~0,2!!currentLine:~3,5! !currentLine:~18!" 
    ) ELSE (
      SET string=!currentLine:~0,2!!currentLine:~3,4! 
      FIND "!string!" labels.txt > nul 
      IF !errorlevel! EQU 0 (
      SET "currentLine=!currentLine:~0,2!!currentLine:~3,5! !currentLine:~18!" 
     ) ELSE (
       SET "currentLine=   !currentLine:~18!" 
     ) 
     ) 
    ) 
    ECHO(!currentline! 
    ENDLOCAL 
    SET "previousLine=%%k" 
) 
)