I need to check to see if a line (or lines) in a file is greater that 80 characters. To do this I need to set the value of %%a equal to a variable. I've noticed that the setting of a variable doesn't take effect until after the loop ha finished. How can I do this without exiting the loop? Here is my code:
Code: Select all
:FOR
FOR /F "TOKENS=* DELIMS=" %%a IN ('TYPE "%FILE%"') DO (
IF /I "%%a"==" " (
ECHO(
SET /A LINES+=1
)
IF /I "%%a" NEQ " " (
CALL :STRLEN %%a
IF /I "%LEN%" GTR "80" SET /A LINES+=2
ECHO %%a
IF /I "%LEN%" LSS "80" SET /A LINES+=1
)
:STRLEN string len -- returns the length of a string
SET "str=A!%~1!"
SET "len=0"
FOR /l %%A in (12,-1,0) do (
SET /a "len|=1<<%%A"
FOR %%B in (!len!) do IF "!str:~%%B,1!"=="" SET /a "len&=~1<<%%A"
)
endlocal&IF "%~2" neq "" (SET /a %~2=%len%) else SET len=%len%